Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76956 invoked from network); 7 Dec 2015 09:38:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Dec 2015 09:38:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:33867] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0F/4C-55814-AA355665 for ; Mon, 07 Dec 2015 04:38:51 -0500 Received: by wmvv187 with SMTP id v187so157306664wmv.1 for ; Mon, 07 Dec 2015 01:38:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=jBA6SFzyk6hK+1ZORrX6GZQa3zAGYOoGoYGSKuKOkFM=; b=MJohqN8MFw1yH3s1nLVGO6AxoB+AU71yWwwpGOeh9fpp5Btk78I4yOElgsBczh73gl kazig8ythqJuolRoOoIY+FEb+kG/Yow2NxBezhnRJ9b5Iw6zFDNzIhixziRR5CTRe78W 9vMrxcYjb+kQhR9KfV6CSNUm1mo9VMfEt4TlRMyfVKV0OY911/MKZkp4yMre6jN+Wo7z 6E+YTk6bxeBTw5wNU7cyhSxWVcGjCuWeSFgXp5CzeSgY8tRL8JWw5ZbN08Y3vMcSwo6V aY3Iv1HAMSTWSI2IXj5Am2Ao0nTt5YN3FR8NgsnsU1w6np9vN4etGBU1O5ut8ep5q8R8 t6MA== X-Received: by 10.194.111.199 with SMTP id ik7mr32378560wjb.167.1449481127495; Mon, 07 Dec 2015 01:38:47 -0800 (PST) Received: from [192.168.0.137] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id jo6sm24352259wjb.48.2015.12.07.01.38.46 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 Dec 2015 01:38:46 -0800 (PST) To: internals@lists.php.net References: Message-ID: <5665536E.5060702@gmail.com> Date: Mon, 7 Dec 2015 09:37:50 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Why PHP 7 yield from still single thread and blocking thread? From: rowan.collins@gmail.com (Rowan Collins) Netroby wrote on 07/12/2015 07:05: > As the RFC said. > https://wiki.php.net/rfc/generator-delegation > The defining feature of Generator functions is their support for > suspending execution for later resumption. This capability gives > applications a mechanism to implement asynchronous and concurrent > architectures even in a traditionally single-threaded language like > PHP. With simple userland task scheduling systems interleaved > generators become lightweight threads of execution for concurrent > processing tasks. > > I wrote a small test. to see if it really concurrent processing any tasks. > the result looks bad. Still single blocking thread. You might be interested in this recent thread: http://marc.info/?t=144342922700001&r=1&w=2 Particularly the discussion of parallel vs asynchronous execution here: http://marc.info/?l=php-internals&m=144354107223549&w=2 Generators / co-routines can be useful when working with asynchronous APIs - that is, functions which start a background task and notify when it is completed - but they do not magically make sequential code parallelizable. Threads - true parallel execution - are much more complex to implement, because of the need to access shared resources in a safe way. So there is nothing surprising in your example not running in parallel: "yield" does not start a new thread, and "sleep" is not an asynchronous API. If instead of sleep you called an asynchronous function, such as a MySQL call set to asynchronous mode, you would indeed see your co-routines running concurrently, as each waited for its respective query result to come back from the database. Hope that helps point you in the right direction to better understand what's going on. Regards, -- Rowan Collins [IMSoP]