Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128941 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 lists.php.net (Postfix) with ESMTPS id E4F601A00BC for ; Fri, 24 Oct 2025 06:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761287687; bh=2e6pgQPCxRrTELUBEaIfdZzZrCqa11n3tatS/KqZ3H8=; h=From:Date:Subject:To:From; b=crt8WFLUbzuuFiwjbG+0965Y5GLAIE4+/z6uMQE/jY7VQMCsoP+HuSj5b8kpcEP+Z e6Ityfgj2hmSLD+beenzikuAcC2Dz/gjVW/vSuQn2gYJjBpZYv0m5CkY5S95f/r+rY 8YsUMlM6LRMaQTZuJjHKkLXTDD7sueKoPUZpq3HrJbtfBXupWn9Tjld6mH6oFr3tNJ I4E81zuy0w4UmyJjlrFd412xARP+AdfQkHnpZvA8fNjeP8+p7mKNdCtY1u9cjLVGXK LqyRrCjLVpkjk/1h3RnjYU+ngbGf9p6NK/lgWtbNstjhZWNM1uRaSzNpuLylt/nVW8 0ZxkWihn5FjRA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 82EAD18004E for ; Fri, 24 Oct 2025 06:34:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) (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 ; Fri, 24 Oct 2025 06:34:43 +0000 (UTC) Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-58de3ab1831so1638850137.3 for ; Thu, 23 Oct 2025 23:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761287677; x=1761892477; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2e6pgQPCxRrTELUBEaIfdZzZrCqa11n3tatS/KqZ3H8=; b=PeNdad/9JSVUjU1UZVBfE7QLF+MR7U9y+n6jyK4KgSSFh7Z20uLF38jTm9iAgN5+rk /7kM/xYJhi8dZFwLokKfhLrMZzvbtuSBPoZ9cqNd8gEhXidOrUdcv2LmBRjQTJuC7ePR X1VXJjkd2eThhoJWPePFVBxQfoF2j+4NwWm77L+kOqUJgeiEhh454sCecLusn9q6EqcV c976JjN/90gcx9Myshjsx8QofZNUpWsAwMIqsyRZDHHElMbIscra4THkDgs8uV/XGKyQ m2iBM6FZh+YGDH20bvDOrPD+6X6KtKQr5dq6hVxA5iQ2ikRdATP5HbPaAxBEN/beglxS FRZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761287677; x=1761892477; h=content-transfer-encoding:to:subject:message-id:date:from :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2e6pgQPCxRrTELUBEaIfdZzZrCqa11n3tatS/KqZ3H8=; b=RMd0FLR6/5HxaPU2ajcNppbkfwaS7T7ej4/CWGhYXsk1c/HXpltG3g8OYTNX0yWxWN Ei37v+iAqpYS0WU7e7KWgHOj6mtIbXMUrewcBOUR2RSi4DVXTTjLvtAM6aQK+fK8qa5n HSmQBhdgxkttRMx8zycxHEYIzhLP2hr8DfpAEEM/Dv8mFwAKbzaXUfzAPjoX4/GzNU+d HoVgNfwywjzrq1jueOJ+ldL8FY68eO44LyR7wt39CKpnOLuP3ZbZh27K2LI/OuJMiRGl Ay0LbxrSYUreK0U7bGgpyT/rNNjoXS2C/Kbd4B4T4ClbTFAixQqHECIDkvq/J5OyLusm Iv9g== X-Gm-Message-State: AOJu0YymluO8leyIyWAfkH8MjpIEsc2bXlTqOm0RbWnEXTDax2RrF0Ul EVdWXFdJyb465ez5GOqHlauwbXvxJjiExhgPBe9a5LGJZq4KqoCd3J3hAfXtybGDbmCwO8FeaqD fNQ3EfDgqkJrEbqpb45BLxpHtnINTt4B4lMGYRgE= X-Gm-Gg: ASbGncvwPSTMzerP3kPIGf7vTvKHhQqZ6koi6XcyvUGlx9Pzmz5Brl5bGT33jytDZOR lcKLL2mWNhFvjSQb2p0K9wTYoZAAtkSwhu4wX0FbftUzqWICPSfwi3aslm4CmqzKor3PHHu3vXl 9wLBemtBPYWYWOs33Sj2/vE8zCm3BEVg9hLq57FwbvY3J0Zwd6HrNtCVPURxRzZPw9jmY/t1H/u +p3omUnUb2NAFw1LJaNfOryKaZCyS/zi6DNm7jh165G/eEk0tWI/yu24TUIU016Jsut+3OJUHFP vGaRqhhrN1IwvUndSCTDMsondw== X-Google-Smtp-Source: AGHT+IFZ5MHEIQ/xDo2Z1Ey/xHVhhdO18gFQvQJgTWvs7r3XV3Nf48z+HY94/05EDNoEodXBMlo3waEVYldhq72dOww= X-Received: by 2002:a05:6102:5e95:b0:537:f1db:76ab with SMTP id ada2fe7eead31-5db3f8c5892mr308852137.14.1761287677288; Thu, 23 Oct 2025 23:34:37 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 24 Oct 2025 09:34:26 +0300 X-Gm-Features: AWmQ_blqDkYTFqdKdOLDIT2zf_J7ajcLccWGtERGJfC9R2X-x8o24c-jEjP9uBA Message-ID: Subject: [PHP-DEV] PHP and parallelism To: php internals , John Bafford , Rob Landers , Aaron Piotrowski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: edmond.ht@gmail.com (Edmond Dantes) Hello everyone, In the TrueAsync RFC 4 thread, John Bafford raised a question about parallelism. I would like to share my thoughts and highlight this branch of the discussi= on. # What is parallelism in the context of coroutines? Parallelism for coroutines means the ability to execute a coroutine in one thread or another (but not simultaneously). In this case, the Scheduler not only manages the execution order of coroutines but also decides which thread from the thread pool should be assigned to a coroutine. # What is the problem? If two different coroutines run in separate threads and write to the same memory region =E2=80=94 that is, to the same PHP object =E2=80=94 it w= ill lead to unpredictable consequences. The issue is that PHP does not control memory access in such cases and effectively allows the programmer to shoot themselves in the head. How can this be solved? ### Object transfer policy The object transfer policy defines how a PHP object can be safely passed to another coroutine. Possible transfer methods: 1. Via parameters 2. Via context 3. Via channels All these methods can be viewed as variations of passing objects through channels (similar to the Erlang model =E2=80=94 no direct sharing). The same policy applies to all methods. An interface is defined to guarantee an object=E2=80=99s =E2=80=9Cthread sa= fety.=E2=80=9D For example, if a coroutine receives an object parameter without this interface, an error occurs. In PHP, there are several possible ways to achieve thread safety: 1. **Ownership transfer**, as in C++/Rust =E2=80=94 the object leaves the current scope and becomes owned by the coroutine. 2. **Proxy-based access**, using a special constructor that creates a proxy object for access to the real one (similar to actors in Swift). 3. **Shared access** with a built-in mutex. This approach requires minimal changes to the language syntax =E2=80=94 in fact, none at all. From a performance standpoint, it is perfectly acceptable for PHP to validate function parameters, so no significant overhead should be expected. The main challenge of parallelism lies in making PHP=E2=80=99s internal sta= te, garbage collector, and memory manager thread-safe. # How does this relate to TrueAsync? At the moment, TrueAsync does not perform additional checks when passing parameters to coroutines. This is a problem =E2=80=94 because once PHP introduces concurrency, developers will start freely using references (&reference) and shared objects. When multitasking is later added to coroutines, it will break existing PHP code that has already been written. Therefore, if PHP truly aims to become multithreaded, its memory ownership model must be carefully designed today. --- Best Regards, Ed