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
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
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 processorsWhat do you think?
__
Raymond
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.
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.orgHello,
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 processorsWhat do you think?
__
Raymond
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):
Thanks for sharing, never heard of tame. Love the await{} block
await {
mysql_query_async($sql, $args, defer($rs));
curl_post_async($url,$data, defer($response));
}
$rows = $rs->fetchAll();
What do you think?
I think it would be really interesting r&d but likely a large undertaking to
get it to work within php
Also async processing makes a lot of sense of in the client since there's a
lot of idle processing power in the pc (dual core cpu etc..)
If many php processes are executing the same async code (server under load),
I'm not sure you'd get a net benefit.
My opinion, server-side caching is faster and more maintainable.
Am 19.08.2011 13:12, schrieb Jonathan Bond-Caron:
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):Thanks for sharing, never heard of tame. Love the await{} block
await {
mysql_query_async($sql, $args, defer($rs));
curl_post_async($url,$data, defer($response));
}
$rows = $rs->fetchAll();
http://de.php.net/manual/en/mysqli.query.php
[...]
With MYSQLI_ASYNC (available with mysqlnd), it is possible to perform
query asynchronously. mysqli_poll()
is then used to get results from
such queries.
[...]
PG should have similar functionality.
Ulf