Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT

Technical Article => Web =>  PHP

Will PHP __autoload() function really affect performance?

  Peter      2012-05-09 11:25:26      2,462    1    0


Regarding to PHP performance, the most frequently discussed is the __autoload() function. Many people say that this function will affect the performance very much, some other people say that opcode will affect __autoload() as well. So we will have some tests on these two.


PHP 5.3.9 -- Launch under fastcgi mode
Nginx 1.1.12


Launch page

eAccelerator(In php.ini) configuration

File structure(each Test file has over 6000 lines of code)

With eAccelerator cache and with __autoload() function loaded

The result after refreshing the web browser
Total Time:0.10401391983032
Total Time:0.10252094268799
Total Time:0.095267057418823
Total Time:0.10013008117676
Total Time:0.096842050552368
Total Time:0.097998142242432
Total Time:0.10348510742188
Total Time:0.096648931503296

With eAccelerator cache and without __autoload() function loaded

The result after refreshing the web browser
Total Time:0.10309100151062
Total Time:0.10285210609436
Total Time:0.10154414176941
Total Time:0.097845792770386
Total Time:0.099545001983643
Total Time:0.10166597366333

The final result : __autoload() function does not affect the performance too much.

Without eAccelerator cache and with __autoload() function loaded

Total Time:0.24992394447327
Total Time:0.25681900978088
Total Time:0.25327301025391
Total Time:0.22580695152283
Total Time:0.22656512260437
Total Time:0.22530484199524
Total Time:0.23080611228943

Without eAccelerator cache and without __autoload() function loaded

Total Time:0.23054909706116
Total Time:0.22633790969849
Total Time:0.23442888259888
Total Time:0.2350070476532
Total Time:0.22897601127625
Total Time:0.23207712173462

__autoload() still doesn't affect the performance very much.


1. __autoload() function doesn't affect performance too much, so it's ok to use __autoload() function
2. opcode will have big impact on code, with opcode,the execution speed of PHP will increase by twice.

Note : some people say that we should not use __autoload() since the maintain cost of it is much higher than the performance cost. I am agree with this statement.

Original author : 川山甲 Source :



Share on Facebook  Share on Twitter  Share on Google+  Share on Weibo  Share on Reddit  Share on Digg  Share on Tumblr    Delicious



Aril [Reply]@ 2012-11-08 21:25:03
:Yup, bookmarks yours as well. We need to rellay sit and comple windows, IIS, Fastcgi, php, and wincache tips. Windows is the bomb but take a lot of work to get it there.Let me know how you'd want to proceed on that. I'll share everything I know. Your site is FAST so I'd definitely like to compare PHP.INI files, etc. at the very least. I know I have a lot of room for improvement at this point. I think my site runs OK right now, but I'd rellay like to tweak it further.


After changing one line of code

By sonic0002
After changing one line of code, everything doesn't feel good.