Hi, I come from sae team of sina. We meet with a problem of APC harklinks mentioned in the buglist of PHP and APC long time ago.
The key word __FILE__ is a magic constants, and it is generated after the php source code is compiled. When the APC is used as a php extension for performence reason, the compiling and executing are independent. So, there are some problems. Please refer to the bug links: http://bugs.php.net/bug.php?id=45421 http://pecl.php.net/bugs/bug.php?id=14055&thanks=3 <http://pecl.php.net/bugs/bug.php?id=14055&thanks=3> I thinks there shoule be a feature in PHP Runtime to get the current executed file name at execute-time(not compile-time). apc_auto_hardlinks_for_php_5.3.5.diff is a patch for PHP 5.3.5, and the patch is to add a new key word "executed_filename". When the following code is running: <?php echo executed_filename; ?> In PHP Runtime, zend_get_executed_filename() is called to returne the current executed file name and being displayed. To fixed the APC hardlinks problem, the other patch auto_hardlinks_for_apc_3.1.6.diff must be used. The filename of opcodearray should be updated when both setting and getting get opcode array to caches in APC. Hope the php patch should be reviewed and php runime will provide the way to get current executed file name at execute-time in the future. Thanks so much. BRs, Chen Lei simpcl2...@gmail.com
diff -uprN php-5.3.5/Zend/zend_compile.c php-5.3.5-sae/Zend/zend_compile.c --- php-5.3.5/Zend/zend_compile.c 2010-11-03 23:40:24.000000000 +0800 +++ php-5.3.5-sae/Zend/zend_compile.c 2011-04-27 14:10:30.000000000 +0800 @@ -5404,6 +5404,20 @@ ZEND_API size_t zend_dirname(char *path, } /* }}} */ +void zend_do_executed_filename(znode *result TSRMLS_DC) /* {{{ */ +{ + zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC); + + opline->result.op_type = IS_TMP_VAR; + opline->result.u.var = get_temporary_variable(CG(active_op_array)); + opline->opcode = ZEND_EXECUTED_FILENAME; + SET_UNUSED(opline->op1); + SET_UNUSED(opline->op2); + *result = opline->result; +} +/* }}} */ + + /* * Local variables: * tab-width: 4 diff -uprN php-5.3.5/Zend/zend_compile.h php-5.3.5-sae/Zend/zend_compile.h --- php-5.3.5/Zend/zend_compile.h 2010-06-10 17:13:22.000000000 +0800 +++ php-5.3.5-sae/Zend/zend_compile.h 2011-04-27 14:10:20.000000000 +0800 @@ -548,6 +548,8 @@ void zend_do_goto(const znode *label TSR void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC); void zend_release_labels(TSRMLS_D); +void zend_do_executed_filename(znode *result TSRMLS_DC); + ZEND_API void function_add_ref(zend_function *function); #define INITIAL_OP_ARRAY_SIZE 64 diff -uprN php-5.3.5/Zend/zend_language_parser.y php-5.3.5-sae/Zend/zend_language_parser.y --- php-5.3.5/Zend/zend_language_parser.y 2010-01-06 04:40:23.000000000 +0800 +++ php-5.3.5-sae/Zend/zend_language_parser.y 2011-04-27 13:53:17.000000000 +0800 @@ -132,7 +132,7 @@ %token T_METHOD_C %token T_FUNC_C %token T_LINE -%token T_FILE +%token T_FILE T_EXECUTED_FILENAME %token T_COMMENT %token T_DOC_COMMENT %token T_OPEN_TAG @@ -765,6 +765,7 @@ common_scalar: | T_NS_C { $$ = $1; } | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; CG(heredoc) = Z_STRVAL($1.u.constant); CG(heredoc_len) = Z_STRLEN($1.u.constant); } | T_START_HEREDOC T_END_HEREDOC { ZVAL_EMPTY_STRING(&$$.u.constant); INIT_PZVAL(&$$.u.constant); $$.op_type = IS_CONST; CG(heredoc) = Z_STRVAL($1.u.constant); CG(heredoc_len) = Z_STRLEN($1.u.constant); } + | T_EXECUTED_FILENAME { zend_do_executed_filename(&$$ TSRMLS_CC); } ; diff -uprN php-5.3.5/Zend/zend_language_scanner.l php-5.3.5-sae/Zend/zend_language_scanner.l --- php-5.3.5/Zend/zend_language_scanner.l 2010-11-18 00:46:19.000000000 +0800 +++ php-5.3.5-sae/Zend/zend_language_scanner.l 2011-04-27 13:50:39.000000000 +0800 @@ -1459,6 +1459,10 @@ NEWLINE ("\r"|"\n"|"\r\n") return T_FILE; } +<ST_IN_SCRIPTING>"executed_filename" { + return T_EXECUTED_FILENAME; +} + <ST_IN_SCRIPTING>"__DIR__" { char *filename = zend_get_compiled_filename(TSRMLS_C); const size_t filename_len = strlen(filename); diff -uprN php-5.3.5/Zend/zend_vm_def.h php-5.3.5-sae/Zend/zend_vm_def.h --- php-5.3.5/Zend/zend_vm_def.h 2010-07-05 17:08:35.000000000 +0800 +++ php-5.3.5-sae/Zend/zend_vm_def.h 2011-04-27 14:11:14.000000000 +0800 @@ -4432,4 +4432,14 @@ ZEND_VM_HANDLER(153, ZEND_DECLARE_LAMBDA ZEND_VM_NEXT_OPCODE(); } +ZEND_VM_HANDLER(154, ZEND_EXECUTED_FILENAME, ANY, ANY) +{ + zend_op *opline = EX(opline); + + char* s = zend_get_executed_filename(TSRMLS_C); + ZVAL_STRING(&(EX_T(opline->result.u.var).tmp_var), s, 1); + + ZEND_VM_NEXT_OPCODE(); +} + ZEND_VM_EXPORT_HELPER(zend_do_fcall, zend_do_fcall_common_helper)
--- APC-3.1.6/apc_main.c 2010-11-30 18:18:31.000000000 +0800 +++ APC-3.1.6-sae/apc_main.c 2011-04-27 15:56:34.000000000 +0800 @@ -559,6 +559,7 @@ static zend_op_array* my_compile_file(ze if (h->type != ZEND_HANDLE_FILENAME) { zend_llist_add_element(&CG(open_files), h); } + op_array->filename = estrdup(filename); return op_array; } if(APCG(report_autofilter)) {
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php