Ah, I've just done a bit of reading in to the PHP MySQL native driver.
It is already possible to do async mysql calls. The documentation in
mysqli::query (http://www.php.net/manual/en/mysqli.query.php) references
MYSQL_ASYNC.
So, if you're just using Mysql, I think there is enough functionality in
PHP today to make the kind of program you're after.
On 05/08/2011 09:20, Jezz Goodwin wrote:
This looks similar to Twisted in Python
(http://twistedmatrix.com/trac/) and NodeJS (http://nodejs.org/) which
are both non-blocking event driven IO engines.
The actual event driven side of things could be written today in PHP.
There's nothing stopping you from writing an event call stack that
manages call backs.
The problem will occur when you try to do any IO in a asynchronous
manner. As far as I know all of the PHP IO operations happen in sync
(there is a pause in the script while waiting for the IO event to
return.)
So, basically async versions of all the needed IO calls (MySQL,
MemCache, FileIO etc) would need to be created which can handle a
callback function. These could be done initially with PECL modules.
(no reason to touch the core to get these working).
Apparently (according to Ryan Dahl of NodeJs) making async calls isn't
as easy as it could be. Especially in MySQL as the base MySQL
libraries in C are blocking (synchronous).
If you're interested in non-blocking IO, I recommend watching the
videos on NodeJs.org
On 05/08/2011 02:54, Raymond Irving wrote:
Hello,
I came across this little library called TameJS (http://tamejs.org/) and
fell in love with the it's syntax. This had me thinking if it was
possible
to add such features to a PHP CLI (or web app):
<?php
await { // wait until all calls within this block is
mysql_query_async($sql, $args, defer($rs)); // call asynchronous
query
curl_post_async($url,$data, defer($response)); // make
asynchronous http
request
}
$rows = $rs->fetchAll();
// do something here
?>
The "await" keyword marks a section of code that depends on externals
events, like network or disk activity, or a timer. An await block
contains
one or more calls to defer.
I think the above syntax makes it easier to write asynchronous apps
that can
take advantage of multiple threads or processors
What do you think?
__
Raymond