我使用twitter-async library对twitter进行了一些oauth调用,但最终,大量内存被耗尽。我尝试运行xdebug执行跟踪,但我觉得这是内存泄漏的地方。
json_decode()使用了47077232字节。好吧。这很好。
但是gettype()呢?为什么这也要使用相似数量的内存呢?
如何才能防止这种情况发生?
脚本循环运行,内存使用量不断增加。我在许多地方使用了gc_collect_cycles(),它正在显示出改进。但是这一次,我不明白为什么会发生这样的事情。
724.1772 47077232 +2118720 -> json_decode() /var/www/html/includes/classes/twitter/EpiTwitter.php:230
724.1926 49157104 +2079872 -> gettype() /var/www/html/includes/classes/twitter/EpiTwitter.php:232
724.1927 49157104 +0 -> property_exists() /var/www/html/includes/classes/twitter/EpiTwitter.php:240
724.1927 49153520 -3584 -> EpiTwitterJson->__destruct() /var/www/html/includes/classes/twitter/EpiTwitter.php:0
724.1949 46714808 -2438712 -> in_array() /var/www/html/cron.php:156发布于 2011-01-14 20:32:34
从documentation
从不使用gettype()来测试某个类型,因为返回的字符串在将来的版本中可能会发生变化。此外,它也很慢,因为它涉及到字符串比较。
相反,请使用is_*函数。
例如,使用is_array、is_string等。
https://stackoverflow.com/questions/4690555
复制相似问题