From: basant dot kukreja at gmail dot com Operating system: Solaris 10 PHP version: 5.2.9 PHP Bug Type: Performance problem Bug description: open/close can be reduced for require_once in ZEND_INCLUDE_OR_EVAL handlers
Description: ------------ There are few ways to include a file. include, require, require_once and include_once. Whey include_once and require_once is used, file is opened by invoking zend_stream_open in ZEND_INCLUDE_OR_EVAL_SPEC_xxx_HANDLER functions. When we use php with apc, apc caches php compiled cache so no open/close call happened for compiled files. However for include_once/require_once files, php still opens the file by calling zend_stream_open. APC checks if the file is in compiled cache, it serves the file. The opened file is simply closed. Net effect is that php opens/closes a file without much use. Reproduce code: --------------- testinc.php : <?php include_once "/opt3/specweb/ecommerce/testinc1.php"; include_once "/opt3/specweb/ecommerce/testinc2.php"; print "Test from testinc.php\n"; ?> testinc1.php $ cat /opt3/specweb/ecommerce/testinc1.php <?php print "Test from testinc1.php\n"; ?> testinc2.php is just a symlink to testinc1.php. Expected result: ---------------- I have found that in ecommerce php benchmark, around 1.5% of the total time is spent for these open/close calls which effectively doesn't do much. If php doesn't use APC, then this optimization doesn't make any sense. However APC, alone can not do this optimization. Here is the dtrace stack trace of open calls. $ x=$pid; sudo dtrace -n "syscall::*open:entry /pid == $x"' / { ustack(); printf("arg0 = %s\n", copyinstr(arg0)); }' dtrace: description 'syscall::*open:entry ' matched 1 probe CPU ID FUNCTION:NAME 1 1458 open:entry libc.so.1`__open+0x4 libc.so.1`open+0x64 libphp5.so`php_execute_script+0x1b0 libphp5.so`php5_execute+0x954 libns-httpd40.so`__1cbAfunc_native_pool_wait_work6FpGpnGpblock_pnHSession_pnHRequest__iI135_i_+0x19c libns-httpd40.so`__1cO_func_exec_str6FpnKFuncStruct_pnGpblock_pnHSession_pnHRequest__i_+0x74 libns-httpd40.so`func_exec_str+0x114 libns-httpd40.so`INTfunc_exec_directive+0x328 libns-httpd40.so`INTservact_service+0x60c libns-httpd40.so`INTservact_handle_processed+0xa8 libns-httpd40.so`__1cLHttpRequestUUnacceleratedRespond6M_v_+0xad8 libns-httpd40.so`__1cLHttpRequestNHandleRequest6MpnGnetbuf_I_i_+0x68c libns-httpd40.so`__1cNDaemonSessionDrun6M_v_+0x254 libnsprwrap.so`__1cGThreadErun_6M_v_+0x28 libnsprwrap.so`ThreadMain+0x14 libnspr4.so`_pt_root+0x1bc libc.so.1`_lwp_start arg0 = . 1 1458 open:entry libc.so.1`__open+0x4 libc.so.1`open+0x64 libphp5.so`_php_stream_fopen+0x1c0 libphp5.so`_php_stream_fopen_with_path+0x290 libphp5.so`php_plain_files_stream_opener+0xcc libphp5.so`_php_stream_open_wrapper_ex+0x1e8 libphp5.so`php_stream_open_for_zend_ex+0x60 libphp5.so`php_stream_open_for_zend+0x28 libphp5.so`zend_stream_open+0x6c libphp5.so`ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER+0x204 libphp5.so`execute+0x3e8 libphp5.so`zend_execute_scripts+0x288 libphp5.so`php_execute_script+0x4cc libphp5.so`php5_execute+0x954 libns-httpd40.so`__1cbAfunc_native_pool_wait_work6FpGpnGpblock_pnHSession_pnHRequest__iI135_i_+0x19c libns-httpd40.so`__1cO_func_exec_str6FpnKFuncStruct_pnGpblock_pnHSession_pnHRequest__i_+0x74 libns-httpd40.so`func_exec_str+0x114 libns-httpd40.so`INTfunc_exec_directive+0x328 libns-httpd40.so`INTservact_service+0x60c libns-httpd40.so`INTservact_handle_processed+0xa8 arg0 = /opt3/specweb/ecommerce/testinc1.php Actual result: -------------- Poor performance because of additional open/close calls. -- Edit bug report at http://bugs.php.net/?id=47660&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47660&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47660&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47660&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47660&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47660&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47660&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47660&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47660&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47660&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47660&r=support Expected behavior: http://bugs.php.net/fix.php?id=47660&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47660&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47660&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47660&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47660&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47660&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47660&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47660&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47660&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47660&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47660&r=mysqlcfg