Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54401 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42412 invoked from network); 5 Aug 2011 09:47:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2011 09:47:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=jezz.g@officechristmas.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jezz.g@officechristmas.co.uk; sender-id=pass Received-SPF: pass (pb1.pair.com: domain officechristmas.co.uk designates 188.39.46.83 as permitted sender) X-PHP-List-Original-Sender: jezz.g@officechristmas.co.uk X-Host-Fingerprint: 188.39.46.83 mail.eclipsehq.co.uk Received: from [188.39.46.83] ([188.39.46.83:11783] helo=mail.eclipsehq.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/A1-31035-F3CBB3E4 for ; Fri, 05 Aug 2011 05:47:44 -0400 Received: from [192.168.2.230] by mail.eclipsehq.co.uk with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.74 (FreeBSD)) (envelope-from ) id 1QpH0k-000ImN-3E for internals@lists.php.net; Fri, 05 Aug 2011 09:48:13 +0000 Message-ID: <4E3BBC3D.5060200@officechristmas.co.uk> Date: Fri, 05 Aug 2011 10:47:41 +0100 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: internals@lists.php.net References: <4E3BA7C2.3040700@officechristmas.co.uk> In-Reply-To: <4E3BA7C2.3040700@officechristmas.co.uk> Content-Type: multipart/alternative; boundary="------------070608050306070206070106" X-Spam-Score: -2.9 X-SA-Exim-Connect-IP: 192.168.2.230 X-SA-Exim-Mail-From: jezz.g@officechristmas.co.uk X-SA-Exim-Scanned: No (on mail.eclipsehq.co.uk); SAEximRunCond expanded to false X-Authenticated-Sender: jezz.g X-Complaints: abuse@eclipsehq.co.uk X-Abuse: abuse@eclipsehq.co.uk (Please include full headers in abuse reports) Subject: Re: [PHP-DEV] TameJS syntax for Async/Parallel execution in PHP From: jezz.g@officechristmas.co.uk (Jezz Goodwin) --------------070608050306070206070106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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): >> >> > >> 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 >> > --------------070608050306070206070106--