PHP 可以上多少门课? [英] How many classes can PHP take?

查看:45
本文介绍了PHP 可以上多少门课?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Google 搜索中没有看到很多关于 PHP 在运行时处理最大类的问题.

Something I haven't seen a lot of on Google search or anything is questions about PHPs max class handling at runtime.

假设我有一个自定义的 arrayaccess 类,它可以容纳多达 8k 个用户"类型的对象.

Say I have a custom arrayaccess class that could house upto 8k objects of type "User".

由于 arrayaccess 类不允许我这样做:

Since the arrayaccess class does not allow me to do:

$d[0]->username = "sam"

当你执行 foreach() 时,只为剩余对象设置类,就像我可以在迭代器中一样,每个循环都会产生一个对象,但数组本身没有对象,它只是分配在数组的每个循环中创建一个新的填充对象(允许您一遍又一遍地重用内存中的相同位置).我只能在 arrayaccess 类中数组的偏移量内的 offsetGet() 方法中设置一个对象.因此,我需要在这个 arrayaccess 类中的任何一点(甚至可能是 20k 个对象)容纳多达 8K 个对象.

And set the class only for a residual object like I can in iterator when you do a foreach() each loop brings out an object but the array itself has got no objects in, it just assigns a new populated object (allowing you to reuse the same spot in memory over and over) in each loop of the array. I can only set a object in the offsetGet() method within the offset of the array within the arrayaccess class. Due to this I would need to house anything upto 8K objects at any one point within this arrayaccess class (maybe even 20k objects).

因此,我的 arrayaccess 类中的每个偏移量都可以是一个表示用户"的对象,并且最多可能有 20k(至少 8k).

So each offset in my arrayaccess class could be an object of say "User" and there could be upto 20k of them (8k at least).

我的问题是: PHP 能够处理这么多的类实例吗?我的意思是这是很多类,我担心它很容易破坏我的内存消耗.

My Question is: Would PHP be able to handle this amount of class instances? I mean this is a lot of classes and I am worried it could easily ruin my memory consumption.

推荐答案

你说的是对象而不是类.

PHP 处理大量对象没有问题,但如果出现问题,只需增加 php.ini 中的 memory_limit.

PHP has no problem dealing with a lot of objects, but if there is an issue just increase the memory_limit in php.ini.

这篇关于PHP 可以上多少门课?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆