I've got a script which receives large file uploads via a PUT request. These files have some processing done on the fly as they are uploading. Sometimes we can detect that a file is invalid in the first few bytes so we die()
with an error message. The only problem is that the client still sends the rest of the data which is a huge waste. Is there a way to shutdown the incoming connection?
Code:
$fp = fopen('php://input', 'rb');
// Do some data checking here
if( <invalid> ) {
fclose($fp);
die('Error');
}
stream_socket_shutdown
looked like it might do the job but it has no effect.
Is there any way to do this? Even if I have to write an extension just for this?
You may want to give the following a shot and see if this terminates the connection properly:
$fp = fopen('php://input', 'rb');
// Do some data checking here
if( <invalid> ) {
fclose($fp);
header("Content-Length: 0");
header("Connection: close");
flush();
die('Error');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With