

PHP Dark Arts: Multi-Processing (Part 2) - raymondmae
http://www.re-cycledair.com/php-dark-arts-multi-processing-part-2

======
ck2
On a somewhat related but more "accessible" possibility, I recently discovered
you can do a trick with register_shutdown_function, remove the execution time
limit and then disconnect the web client entirely, while continuing
processing.

So using ajax on the client side, you could say open a dozen connections and
purposely disconnect them while continuing processing, technically in parallel
(though not in the same process).

Can't fathom a practical use for this at the moment but it's still an
interesting ability.

~~~
viraptor
> Can't fathom a practical use

Update anything that the client doesn't need to wait for. Visitor stats, page
view stats, notifications about sent messages if you use some distributed
queues, any deferred post-processing...

------
TamDenholm
[http://www.re-cycledair.com/php-dark-arts-multi-threading-
pa...](http://www.re-cycledair.com/php-dark-arts-multi-threading-part-1) For
those that missed part 1.

------
atomical
Don't bother trying to implement something complicated with multi-processing
in PHP. The article defeats itself: "If you need multi-threading, use a
different language."

~~~
jawngee
Oh yeah? Why not?

We built a self-scaling multi-processing conversion system entirely in php @
<http://massify.com/>. In like 2-3 weeks. Had it deployed a week after that.
It's been running for 2+ years with zero maintenance and handles all of the
video, image, audio and office docs -> swf conversions. It's not a trivial
system, but for what it does is simple enough to be beautiful despite the
language it was built in.

It was designed to completely share nothing, message based, isolated, fault
tolerant. I could go into the architecture more if you are interested.

Now Massify is not youtube scale, but this could scale to that size with minor
adjustment (mostly with balancing uploads to the upload handlers). In it's
current incarnation, the thing will scale by itself to whatever restraint
Amazon puts on it.

We had one film contest were we watched the thing spin up a ton of ec2
instances and then tear them down when it was done. It was a little like
watching an army of media converting robots.

So I was going to write this long winded thing about why I used PHP to do it,
but at the end of the day it really doesn't matter. All that matters is that
it works and works well. If writing this kind of stuff in PHP doesn't appeal
to you, then cool, good for you. But your notion that it can't be done or done
well is not grounded in any kind of reality.

~~~
troels
Interesting. I would like to see some more details on that solution?

------
robryan
Pretty much just a thin abstraction of c functions.

