Server push using PHP
| From: | Robert | Date: | Mon, 25 Sep 2000 14:40:30 +0000 |
| Subject: | Server push using PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17428@lists.php.net to get a copy of this message | ||
I am working on a project that needs to use the "server push" mode. What
I need to do is send a series of jpg's to a client such that each new jpg
replaces the previous one. What the client sees is a low rep rate
"movie". The code I have at this point, nearly works. I can send a
series of images, however, the php script occasionally stops before it
sends the entire list of images.
PHP's behavior is strange, because it's pretty consistant about which
images it stops on. If I remove the "offending image" from the list, the
script will continue with later images, until it hits another "offending
image". About 1 image in 125 is an offending image, and stops the script.
One other clue, is that the "offending image" is the one shown on the
browser when the transfer stops. In other words, "offending images" can
be displayed, but they prevent the script from proceeding to the next
image.
At first I thought the problem was that PHP was timing out. However adding
set_time_limit() has made no difference, and besides the script stops
at a certain image, not after a certain number of images, or after a
certain amount of time.
Then I suspected my browser was at fault, but I have also generated a perl
cgi script to do the server push function, and it runs thru the "offending
images" just fine. Is it possible that the php function readfile() has
trouble with transfering certain charactor codes?
Any assistance would be greatly appreciated. Details are below.
Best Regards,
Robert
--------------------------------
PHP script I am using to send the images:
<?php
Header("Content-type: multipart/x-mixed-replace; boundry=--myboundryishere");
# parms passed in the URL:
# $dir the directory to read the image files from
# $min the index number of the first file to display
# $max the index file of the last file to display
# $rate the number of milliseconds between images
$l =
ls $dir;
$files = explode("\n", chop($l));
$micro = 1000 * $rate;
set_time_limit( 3600 );
echo "--myboundryishere\n";
while( list( $no, $line ) = each( $files )) {
if( ($no >= min) && ($no <= $max) ) {
echo "Content-type: image/jpeg\n\n";
readfile("$dir/$line");
echo "\n\n--myboundryishere\n";
usleep($micro);
}
}
?>
----------------------------
Here is the line used to invoke this script:
echo "<img
src=\"scan_image.php?dir=$dir&min=0&max=20000&rate=250\">";
-----------------------------
Here is the partial output from phpinfo() on this server:
PHP Version 4.0.2
System Linux xxx.xxx.xxx 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST
2000 i686 unknown
Build Date Sep 23 2000
Configure Command './configure''--with-mysql' '--with-apxs'
'--enable-magic-quotes'
'--with-ndbm'
Server API Apache
Virtual Directory Support disabled
Configuration File (php.ini) /usr/local/lib
Path
ZEND_DEBUG disabled
Thread Safety disabled
-------------------
The OS was built from RedHat 6.2.