Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126434 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id CA2321A00BC for ; Mon, 17 Feb 2025 19:32:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739820568; bh=Hy8ObDU6JeSBWBZN0M8Xx01HlW4jsS87VzzLhdgDI14=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cBjyg3Cmk+SPrnIuLCxDSo9Bs+ct9aHE1FiruLVSI8LfNIHl+4KthvuABwHS2vtPw 1h8lG1nQvQHUWrlm66wmVo4ENXX19CzP3sfEdAMl2AIr5jtq9y67tqMaWKe+ZFhwCQ kbSioDADr62DeQDHemW0Ak8Cg0AaiMCgkXxZTssvrWqt5Ay0DfFpbA9JDE3e56JbiZ lLi5LTz81ynK+Z6pMaYiHKtEMIQpE75OX9rwbltOrXXRIhzn8ho5xL6zYHdcPUyWeg tGA1yJIp8IApXbbxoqBNtgGlz28m3th4QhXqFExjAySva50DUjltYdm2XcF1dUXl4T DHiSB7X8wQduA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7F5B4180072 for ; Mon, 17 Feb 2025 19:29:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Feb 2025 19:29:27 +0000 (UTC) Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e549be93d5eso5093600276.1 for ; Mon, 17 Feb 2025 11:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739820728; x=1740425528; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+b0WIt3sD3hzTYfVEQTmLZjv8Jt1b+xKt74tUR/QtQs=; b=QMOtviiVYyiayC1YljimybxtbEFtLoqt6kYg0R1AK1TzjPVp5J03OTGEhpK5BjrMRu FpBUsLZbkqJRZfKfO5AXUCQM6UaLkzvBWIZ1vsqqIaPLfG8x40eCZUHV6TMsnBDxbTMB ZDkIXtQNtmnGr69pmIS1fQnkklIAejMPuWG1uT5rMk0uJ1H4P/226NdLIsvumLnT/uPd K9KA5hP76eXatsUZPXGD6KgLbNv3W0Mjp19hH6diIs3k0whgWq+DaWadBQ6mFT4wPzub fTiSCfX6+ftNM7DY2eNYlYDBrk1Klzbr2zP9997lftscbbg+xIiubtXF+t5Bokm1rDc/ wSDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739820728; x=1740425528; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+b0WIt3sD3hzTYfVEQTmLZjv8Jt1b+xKt74tUR/QtQs=; b=s6hBIeCJGWQUhQc5HRaouDiW4xDRCBCIZuR0SgrjZxihOTxzDrxdf6GGbFDWckACKE 1hyFWamln9FWzK59TavUcj/0w/iXD5MgVGQDVAqQmvo+BmB5pNPfuJH/AGJi1lywbbJU DMTKfFQWCyxYSiivlNUZz4HyVfSavkdZZZtM7LOrnsRvk8I+OVhoI8nkVqS5Brefj4fd cXAnBgrcwHsaQV9twmIaX6krcU1fKntAcfBg709ksIFTE/B3mHSCwnEaFEGVDn9TOCIk 7cNt9wMvB9HD4K7ie3WN+4hxvHxc728k0HZk8FNuZadYLxqy7MLIE/oqvnoAT+F000M+ fndQ== X-Gm-Message-State: AOJu0Yx4QIKNts4f0wtq7BV8/oLyX9krFwmGKK1icO5x4OcScWqd1FcE nc2N139PxiiuQCE/GUEGiiBoN/vu1HM/pf35ijxVkTa2FtGvdGAogW7xJl3LTN9tt6zrIP7wRke KFXErMa9wMfSW9v0HWO111zd8J4o= X-Gm-Gg: ASbGncu72OC/HIma73JuFbaFSUnHbU1iFa5eChZ2FAc/BV9sFO2pMdPLp/ZSGDtSRXF qLxRN7MT2qcQx7/Dh7SxaHQRizHK/R+pSJMD8DnLNsb/0yLcRjsswQ/+xJMVYecvtwLVXV/VN X-Google-Smtp-Source: AGHT+IF6S34Aq2TA98hzwCo7Um6MVdxHaf6fJ1lhT2DwcstARKGN9YX5g2W1YpVu+BWgw0J4LmA+9UZwkNFPCIBGIxs= X-Received: by 2002:a05:6902:20c5:b0:e5b:1dda:8f6e with SMTP id 3f1490d57ef6-e5dc92ed36amr9580182276.39.1739820727910; Mon, 17 Feb 2025 11:32:07 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <24becc76-b67f-4805-b33b-cd4f9f6d0b30@scriptfusion.com> <88656d56-7bfc-4966-8fea-4b4ea883f1f1@scriptfusion.com> In-Reply-To: <88656d56-7bfc-4966-8fea-4b4ea883f1f1@scriptfusion.com> Date: Mon, 17 Feb 2025 21:31:57 +0200 X-Gm-Features: AWEUYZmhp_FNAXw2OA4m5sHZyjHb4dll9CnlKd3E10TmJbNCqHr3Nu35wORsUp8 Message-ID: Subject: Re: [PHP-DEV] PHP True Async To: Bilge Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000075ce11062e5b9497" From: edmond.ht@gmail.com (Edmond Dantes) --00000000000075ce11062e5b9497 Content-Type: text/plain; charset="UTF-8" > There should be no perceptible difference between a blocking sleep(10) and an async sleep(10), so what backwards compatibility are you referring to? For example, the behavior of the code below will not change. The code will execute sequentially, and context switching will only occur when resume/ suspend is called. However, when the Scheduler is activated, this behavior changes. Now, calling sleep() inside a Fiber will lead to a context switch. If the activation of the Scheduler is implicit, previously written code may not work as the developer expects. start(); echo "Fiber suspended with: $result\n"; sleep(10); $fiber->resume(); echo "Fiber finished\n"; --00000000000075ce11062e5b9497 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>=C2=A0 There should be no perceptible difference between a blocking sleep(10) and = an async sleep(10), so what backwards compatibility are you referring to?

For example, the behavior of the code below will not c= hange. The code will execute sequentially, and context switching will only = occur when resume/suspend is called.

Howeve= r, when the Scheduler is activated, this behavior changes. Now= , calling sleep() inside a Fiber will lead to a c= ontext switch.

If the activation of the Scheduler is imp= licit, previously written code may not work as the developer expects.


<?php

$fiber =3D new Fiber(function (): v= oid {
=C2=A0 =C2=A0 echo "Start fiber\n";
=C2=A0 =C2= =A0 sleep(1);
=C2=A0 =C2=A0 Fiber::suspend("Paused");
=C2= =A0 =C2=A0 echo "Resume fiber\n";
});

$result =3D $fibe= r->start();

echo "Fiber suspended with: $result\n";

sleep(10);

$fiber->resume();

echo &q= uot;Fiber finished\n";
--00000000000075ce11062e5b9497--