> I'm sure we can eliminate those seeks.  Are there any other areas in the
> streams code that you can see that could do with a syscall tune-up?

Ok, found two more.  In _php_stream_fopen() we fstat() the script to be 
opened:

    realpath = expand_filepath(filename, NULL TSRMLS_CC);

    fp = fopen(realpath, mode);

    if (fp) {
        /* sanity checks for include/require */
        if (options & STREAM_OPEN_FOR_INCLUDE && (fstat(fileno(fp), &st) == -1 || 
!S_ISREG(st.st_mode))) {
#ifdef PHP_WIN32
            /* skip the sanity check; fstat doesn't appear to work on
             * UNC paths */
            if (!IS_UNC_PATH(filename, strlen(filename)))
#endif
                goto err;
        }
        ret = php_stream_fopen_from_file_rel(fp, mode);


That sequence of code is a trainwreck.  The expand_filepath() ends up 
doing an lstat() on every component of the path and then the file itself, 
and then we fstat() the file.  I can't afford the realpath() here, so I 
turn it off in expand_filepath(), but I don't think the fstat() is needed 
there.

Then right after that in _php_stream_fopen_from_file() we have:

#ifdef S_ISFIFO
    /* detect if this is a pipe */
    if (self->fd >= 0) {
        struct stat sb;
        self->is_pipe = (fstat(self->fd, &sb) == 0 && S_ISFIFO(sb.st_mode)) ? 1 : 0;
    }
#endif

which does yet another fstat() on the file.  At the very least, this one 
should use the result of the previous one.  Basically if these checks are 
still needed, we need a stat cache here.  

There is a 3rd fstat() after that, but I can't really make any sense of 
the backtrace to it:

#0  0x202d0c58 in fstat () from /usr/lib/libc.so.4
#1  0x202e42e6 in __swhatbuf () from /usr/lib/libc.so.4
#2  0x202e4236 in __smakebuf () from /usr/lib/libc.so.4
#3  0x202d454f in __srefill () from /usr/lib/libc.so.4
#4  0x202b3ea6 in fread () from /usr/lib/libc.so.4
#5  0x203f9bb4 in yy_get_next_buffer () at Zend/zend_language_scanner.c:5359
#6  0x203f98cd in lex_scan (zendlval=0x9fbfd770) at Zend/zend_language_scanner.c:5193
#7  0x20401814 in zendlex (zendlval=0x9fbfd76c) at 
/homes/rasmus/php4/Zend/zend_compile.c:2459
#8  0x203f38e8 in zendparse () at /home/y/share/bison.simple:432
#9  0x203f6685 in compile_file (file_handle=0x9fbff758, type=2) at 
/homes/rasmus/php4/Zend/zend_language_scanner.l:348
#10 0x2040b3a6 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at 
/homes/rasmus/php4/Zend/zend.c:860
#11 0x203e41ce in php_execute_script (primary_file=0x9fbff758) at 
/homes/rasmus/php4/main/main.c:1591
#12 0x204235d6 in apache_php_module_main (r=0xdc040, display_source_mode=0)
    at /homes/rasmus/php4/sapi/apache/sapi_apache.c:55
#13 0x2042419e in send_php (r=0xdc040, display_source_mode=0, filename=0x0)
    at /homes/rasmus/php4/sapi/apache/mod_php4.c:617
#14 0x204241fe in send_parsed_php (r=0xdc040) at 
/homes/rasmus/php4/sapi/apache/mod_php4.c:632
#15 0x48e84 in ap_invoke_handler (r=0xdc040) at http_config.c:518
#16 0x59cec in process_request_internal (r=0xdc040) at http_request.c:1352
#17 0x59d47 in ap_process_request (r=0xdc040) at http_request.c:1368
#18 0x52977 in child_main (child_num_arg=0) at http_main.c:5229
#19 0x52b18 in make_child (s=0xa4930, slot=0, now=1046217441) at http_main.c:5400
#20 0x52c49 in startup_children (number_to_start=25) at http_main.c:5498
#21 0x53165 in standalone_main (argc=2, argv=0x9fbffa80) at http_main.c:5859
#22 0x538ec in main (argc=2, argv=0x9fbffa80) at http_main.c:6246

-Rasmus


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to