Eliminating stat() calls in opcode caches for include_once
| From: | Dmitry Stogov | Date: | Wed, 21 Nov 2012 14:15:54 +0000 |
| Subject: | Eliminating stat() calls in opcode caches for include_once | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-64026@lists.php.net to get a copy of this message | ||
Hi Pierre,
To avoid stat() syscalls the opcode cache has to override
zend_resolve_path() and zend_open_stream() callbacks with something like
the following functions.
static char* my_resolve_path(const char *filename, int filename_len
TSRMLS_DC)
{
if ((EG(opline_ptr) &&
*EG(opline_ptr) &&
(*EG(opline_ptr))->opcode == ZEND_INCLUDE_OR_EVAL &&
((*EG(opline_ptr))->extended_value == ZEND_INCLUDE_ONCE ||
(*EG(opline_ptr))->extended_value == ZEND_REQUIRE_ONCE))) {
CACHE_BUCKET *b = OPCODE_CACHE_FIND(filename TSRMLS_CC);
if (b) {
return b->real_path;
}
}
return orig_resolve_path(filename, filename_len TSRMLS_CC);
}
static int my_stream_open(const char *filename, zend_file_handle *handle
TSRMLS_DC)
{
if ((EG(opline_ptr) &&
*EG(opline_ptr) &&
(*EG(opline_ptr))->opcode == ZEND_INCLUDE_OR_EVAL &&
((*EG(opline_ptr))->extended_value == ZEND_INCLUDE_ONCE ||
(*EG(opline_ptr))->extended_value == ZEND_REQUIRE_ONCE))) {
CACHE_BUCKET *b = OPCODE_CACHE_FIND(filename TSRMLS_CC);
if (b) {
handle->type = ZEND_HANDLE_FILENAME;
handle->opened_path = estrdup(b->real_path);
return SUCCESS;
}
}
return orig_steam_open(filename, handle TSRMLS_CC);
}
Thanks. Dmitry.