Hi, I hope this is the appropriate list.  I have been banging on this issue
for quite some time.   Basically, I have an intermittent problem with
various stream calls.

Essentially, I see massive CPU utilization while waiting to get data from
some http locations, under some circumstances.

This is on Linux, (currently using apache 2.0) I have tried with curl on and
off, and php versions 5.2.1 through 5.2.5

I have used the following log code:

    public function logentry($entry)
    {
        $times = posix_times();
        $time = microtime();

        $this->log[] = array($time, $entry, $times['utime'],
$times['stime']);

    }

In my logging class to track my progress through the reading function.

Note that this problem occurs with stream_get_contents, fread, fgets, or
just about every other stream reading function I can think of, and it is
highly intermittent and depending on the web site.  Some slower responding
sites tend to reproduce the problem considerably more readily.

The following is my httpread function: (I've been playing with stream_select
but the function performs similarly without it)

function getPage($file, $maxlen = 256000, $timeout = 10)
{
    global $log;

    $log->logentry("entering get page $file");
    $conex =fopen($file, "r");

    $log->logentry("$file opened");
    $data = '';

        if ($conex === false) {
           echo ("error in file read");

            return false;
        }

    stream_set_timeout($conex, $timeout);
    //$data = stream_get_contents($conex, $maxlen);
    //

    if (stripos($file, "http") !== 0)
    {
        $data = stream_get_contents($conex);
        fclose($conex);
        return $data;
    }
    $output = "";

    while(!feof($conex))
    {
        $read = array($conex);
        $write = NULL;
        $except = NULL;

        $log->logentry("starting stream select");

        $streams = stream_select($read, $write, $except, 10);
        $log->logentry("stream select end result: $streams");

        $meta = stream_get_meta_data($conex);

        if ($streams !== false) {
            $log->logentry("getpage start read");
            $buf = fread($conex, 4096);
            $log->logentry("read length:".strlen($buf));
            $data.=$buf;
        }
    }

    $log->logentry("$file contents retrieved");
    echo ($output);
    fclose($conex);

    return $data;

}

When I call the function with the following url as an example:

http://mobile.wired.com/item.jsp?key=po opened

(And this happens without spaces in the name as well, this was just one
sample url)
I have seen cases where the first fread takes 7-8 seconds of system cpu,
over a period of about 13 seconds of system time.

My expectation would be that fread should block, mostly sleeping if there
isn't data available (which I do see happening in a number of non problem
cases)  

Could someone please point me in the correct direction to track this down,
or even report it to?   Or at least, clue me in if it is expected behaviour.

Thanks, and apologies if this is going to the wrong list.  

Ron Radko

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

Reply via email to