So the Microsoft Developer Summit has started, they wine and dined us last night, then shuffled us onto a bus at the criminally early 7:20am (Sara Golemon didn't make it onto the bus). I like the focus this year, last year they seemed to have talks coming in from all over the place (perhaps whomever was available), this year is focused specifically on the PHP developer, and what we care about. There's a few talks from non MS employees (my friend Dave Fetterman from Facebook is giving a talk).
You've probably heard of the setting in php.ini ignore_user_abort, and how it allows you to ignore a user aborting page load and thus terminating your script mid way through. Today I found out that didn't quite mean what I thought that meant.

I was under the impression that when the user hit stop, the script stopped. Which is: bad, and wrong. PHP doesn't detect that the user has terminated the connection, it has no clue, it obligingly continues processing along, until it attempts to send information to the user. Now, just because you have an echo statement, doesn't mean that information is necessarily being sent to the user, buffering (not necessarily output buffering, PHP and your web server also implement some buffering) will probably catch it. It's not until that buffer is filled, or you call something like flush() that information is actually sent, and thus PHP would know the user has aborted.

When might you want to ignore a user abort? Well, simply put, any situation where you're executing a series of sequential actions and stopping in the middle would leave your application in a bad state (transactions are the database solution for this, they're simply rolled back if you disconnect without committing (unless you're using a persistent connection)).

In short, the user aborts when they close their browser, hit stop, etc. PHP however doesn't know the user has aborted until it actually attempts to send them data.

Hi, I’m Paul Reinheimer, a developer working on the web.

I co-founded WonderProxy which provides access to over 200 proxies around the world to enable testing of geoip sensitive applications. We've since expanded to offer more granular tooling through Where's it Up

My hobbies are cycling, photography, travel, and engaging Allison Moore in intelligent discourse. I frequently write about PHP and other related technologies.

Search