Jump to content

Connection handling


cmancre

Recommended Posts

Hi, today I've read the "Connection handling" PHP section at http://us2.php.net/manual/en/features.connection-handling.php and tried my self to prove it.

 

from PHP documentation

"When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button."

 

I did a simple code

 

test.php
<?php
sleep(20);

// DB connection
// INSERT a line into a table

echo "hello";
?>

 

When i run test.php and hit browser stop 5 seconds after the script stops indeed on the client side but on the server side the DB line is inserted after the 20 seconds. Looks like the script didn't end when I pressed stop.

 

As I understood from the documentation, a script should stop if the user hits stop, for that reason there is a function named ignore_user_abort() to ignore that user behavior and keep the scripts running until they finish or timeout.

 

Isn't this strange according to the documentation?

 

NOTE: I'm using PHP5.1.2-1ubuntu3.15

 

Link to comment
https://forums.phpfreaks.com/topic/176873-connection-handling/
Share on other sites

It depends on lots of things, and there's not really a reliable way inside of PHP to know if a connection dropped or was aborted.

 

 

Apache handles the actual connection, so it's up to Apache to notify PHP that it dropped, and then PHP handles it how it wishes.

 

 

The problem though is that sometimes Apache doesn't realize the connection is dropped until it tries to write/read something to/from the socket and realizes it can't.  Or, it could theoretically choose not to notify PHP that the connection dropped.

Link to comment
https://forums.phpfreaks.com/topic/176873-connection-handling/#findComment-932630
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.