register_shutdown_function()

From: Date: Fri, 01 Sep 2000 19:35:25 +0000
Subject: register_shutdown_function()
Groups: php.general 
Request: Send a blank email to php-general+get-14864@lists.php.net to get a copy of this message
I am running Apache/1.3.12 (Unix) PHP/3.0.16 on a Linux machine. I'm having trouble getting register_shutdown_function() to execute the registered function when the user aborts a download. Here's a demo script that creates a 1 MB temp file from /dev/zero and then passes it to the client. Upon exit, the shutdown function, "exec_on_exit", is called to remove the temp file. If the downlod is allowed to complete, the temp file is removed so I'm confident that I've registered the function, however if the download is aborted (click STOP while the download is in progress), the shutdown function is apparently NOT being invoked and thus the temp file is NOT removed. What have I done wrong? ---- <? function exec_on_exit() { global $shipfile; if(file_exists($shipfile)) { unlink($shipfile); } } register_shutdown_function("exec_on_exit"); $shipfile = tempnam("/tmp", "Zero"); $command = "/bin/dd count=1024 bs=1024 if=/dev/zero of='$shipfile'"; exec($command, $out, $retval); if($retval != 0) { # error handling echo "something bad happened\n"; exit; } $clength = filesize($shipfile); header("HTTP/1.0 200 OK"); header("Content-Length: " . $clength); header("Connection: close"); header("Content-Type: application/octet-stream"); $command = "/bin/cat $shipfile"; passthru($command); ?>

« previous php.general (#14864) next »