|
From: <php...@li...> - 2010-02-05 06:24:18
|
Hi,
I'm doing a fairly simple streaming download, looping for a number of
different files, and I'm getting sporadic, unrepeatable severe errors in
PhpCGIServlet.
The code will successfully download some files, or parts of some files,
but will sometimes cause a crash. It might download 850MB without a
hiccup, or fail partway through a file at 20MB. If I rerun the code, it
might download the file it previously failed on, or I might need to run
it two or three times to get it to work, then it might download all
other files with no problems.
The code has been tested using the most up-to-date JavaBridge,
php-script and php-servlet jar files and the error still occurs. The PHP
has been tested in Apache webserver and there is no evidence of the
error there. Tomcat is running on a VMWare instance with PHP-CGI, and
Apache is running on the host machine with the Apache PHP server module.
Any advice would be welcome.
Using:
PHP 5.2.10
Tomcat 6.0.20
Apache 2.2.10
Cheers,
Mark...
Extract of error log:
INFO: PHP Warning: unlink(sync.lck) [<a
href='function.unlink'>function.unlink</a>]: Permission denied in
C:\player.php on line 15
Feb 5, 2010 12:53:19 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextDestroyed()
Feb 5, 2010 12:53:19 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextDestroyed()
Feb 5, 2010 12:53:19 PM org.apache.catalina.core.ApplicationContext log
SEVERE: Servlet PhpCGIServlet threw unload() exception
javax.servlet.ServletException: Servlet.destroy() for servlet
PhpCGIServlet threw exception
at
org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1413)
at org.apache.catalina.core.StandardWrapper.stop(StandardWrapper.java:1739)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4563)
at
org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
at
org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1248)
at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1219)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:316)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:633)
at org.apache.catalina.startup.Catalina.start(Catalina.java:608)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NullPointerException
at php.java.bridge.Util$Process.getOutputStream(Util.java:1071)
at php.java.servlet.fastcgi.ChannelFactory.destroy(ChannelFactory.java:149)
at php.java.servlet.fastcgi.FastCGIServlet.destroy(FastCGIServlet.java:296)
at php.java.servlet.PhpCGIServlet.destroy(PhpCGIServlet.java:195)
at
org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1394)
... 20 more
The code extract is here. The error is occuring in the '// Chunk
download' loop:
$fs = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fs) {
$this->writeDebugInfo("FAILED: ", $errstr . '(' . $errno .
')');
} else {
$out = "GET $file HTTP/1.0\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fs, $out);
$fm = fopen ($temp_file_name, "w");
stream_set_timeout($fs, 30);
while(!feof($fs) && ($debug = fgets($fs)) != "\r\n" ); //
ignore headers
while(!feof($fs)) {
$contents = fgets($fs, 4096); // Chunk download
fwrite($fm, $contents);
}
fclose($fm);
$info = stream_get_meta_data($fs);
fclose($fs);
if ($info['timed_out']) {
// Delete temp file if fails
unlink($temp_file_name);
$this->writeDebugInfo("FAILED: Connection timed out: ",
$temp_file_name);
$this->writeDebugInfo("stream info: ", $info);
} else {
// Move temp file if succeeds
$media_file_name = str_replace('temp/', 'media/',
$temp_file_name);
rename($temp_file_name, $media_file_name);
$this->writeDebugInfo("SUCCESS: ", $media_file_name);
$this->writeDebugInfo("stream info: ", $info);
}
}
|