PHP Classes

Leverage JS and Native PHP for Asynchronous Programming

Recommend this page to a friend!

      PHP Classes blog  >  Accelerate scripts ru...  >  All threads  >  Leverage JS and Native PHP for...  >  (Un) Subscribe thread alerts  
Subject:Leverage JS and Native PHP for...
Summary:Leverage JS and Native PHP for Asynchronous Programming
Messages:2
Author:David Gibbons
Date:2010-10-28 13:43:32
Update:2010-11-01 23:42:30
 

  1. Leverage JS and Native PHP for...   Reply   Report abuse  
Picture of David Gibbons David Gibbons - 2010-10-28 16:20:03
I find it rather unbelievable that adding an intermediary proxy layer to implement asynchronous PHP will 'accelerate' any script unless it's running on a *very* heavily overloaded and poorly optimized server.

Why would you not leverage the functionality built into native javascript and split out PHP tasks than can be run synchronously into multiple javascript calls against separate PHP scripts (running on separate vhosts if necessary for load management)? This method would implement asynchronous calls natively.

Using native PHP, if you have say four database calls that block each other, you could use the session or a separate database table or even a memcache variable to communicate status messages between the scripts. This way there's no middle man, no extra memory usage for a proxy layer and a completely native implementation not influenced by any PHP libraries that may be incompatible with callback functions.

  2. Re: Leverage JS and Native PHP for...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-11-01 23:42:30 - In reply to message 1 from David Gibbons
There seems to be a misunderstanding.

The only case on which calling a parallel process using Gearman was suggested is to overcome current PHP limitations of database access extensions that only allow synchronous calls.

It would be faster calling processes asynchronously because you would be able to make multiple calls without having to wait for one before proceeding to the next.

For types tasks like accessing files or network acccesses, in PHP it can be done asynchronously without depending on JavaScript. JavaScript and namely Node.js were only mentioned to demonstrate that it is possible to do it without using any multi-thread support or multiple scripts running in parallel.