Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31142 invoked from network); 5 Aug 2011 08:20:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2011 08:20:51 -0000 Authentication-Results: pb1.pair.com header.from=jezz.g@officechristmas.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jezz.g@officechristmas.co.uk; spf=pass; 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:63649] helo=mail.eclipsehq.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/00-31035-DD7AB3E4 for ; Fri, 05 Aug 2011 04:20:47 -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 1QpFeB-000I4k-Ku for internals@lists.php.net; Fri, 05 Aug 2011 08:20:51 +0000 Message-ID: <4E3BA7C2.3040700@officechristmas.co.uk> Date: Fri, 05 Aug 2011 09:20:18 +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: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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) 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 >