Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129746 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 6967B1A00BC for ; Sat, 10 Jan 2026 08:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1768033179; bh=tT546ZvVifnB9Wr3qGVUformMqU8oH0il7Ch+oJptz8=; h=From:Date:Subject:To:From; b=KGPJu+XfutXgi4cTamFWnktxo0HuXyzVeHUqB+41YNA5xkClx2fxYjCu8+cUr9goZ Gd9J4v43nz1wmm83w+kijkCgXb9mMH70rY8sKVlpPMdxIE3Po90dwyFoAFNPj2OTk2 dJNOU2PWNPjRoo//wjny9SU51b6ySUdViUEX6VUsDxOcEJIeq4LLbo+G0dKT8xtBe2 hvoR0nZ1Y3oGCj8pUIEfWQIjc0VSBWJdlpZ5V4aNTnRsaLWpSOmeUS4mX2urSKoAF0 thiy86bw7f4KUzQwRt7tNYtZGsapCZ2+o5ohbY2QIHvbSqHCrvpF0pZqkrM/Jy4c30 jgGG6NeKs6+7w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0801A18007E for ; Sat, 10 Jan 2026 08:19:38 +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, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44]) (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 ; Sat, 10 Jan 2026 08:19:24 +0000 (UTC) Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-121b14d0089so5216991c88.0 for ; Sat, 10 Jan 2026 00:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768033158; x=1768637958; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=gnQZXDxnnbag+62tcZhAPgHa8kc6rNeqq/MjzYQkaTk=; b=FybCe5TR3YMjFueFd68v39ub3WIoPz1XSl596js1OwlpOuqnfTNAmhWxQv0Vi5Y429 8wvCQKMlffaQ9pFONon/Atn0g5kvz8I3Ve7PMj2q4PoGjW7vIef/GJH9WThcpkPBHO0l Qk5MC1EGMDr1OtpaQS9R+m7mrgTSNNNL7doQtIjBEIeIpZxSpqU6TujAPnM38jbv9VdT jq5e+oxA/PFLMI6OOTiXPgtW4g52WvjAi55GyzVWkPCmgH/suNam3invHGOQNEUz//WX 1IrwPDumR1Rh9xiefEtW4gkyi/fQuGkB8UehJwVIYNlNPTe6dQScRXmRrslH4kAyADWD jf8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768033158; x=1768637958; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gnQZXDxnnbag+62tcZhAPgHa8kc6rNeqq/MjzYQkaTk=; b=UAOXAD59qLNtLejITNOR61bT+LVZfstRSLeFhenKRB2OrVIny1Q3msuojOBE2djTEi Nh9LANA1bewFhO7XlQAm+MFBYVlduCuwpr80fAgScmPET3QCZDwUoe81xw6sqBAEJ3DL wzb4aWV3CsVJZRuF3dzhoCGtRSFGIx/kUhkK8+GZExpUezNvHjwAoS3clZ5rQzH9BQPi B6VaK1PJMXjG2KqOQ9GdoOkr4+WNBJU/QxoGg/QENBGnImNS3TDnTtQdxzhK4mgYUn+a HxAwGT0Fg3m5oQ/bMcieVm2j+VKOb9sYG1ZchOgVkYowl1+4W7q+FutT6KXA3LYjk6ve EwJQ== X-Gm-Message-State: AOJu0Ywv+MMqP47DmGz4ZY02L5g9RDXLH8q94w0EbC34ktNHfZzRcclR UjsC5sJFOpiSbx0246hMPcO/n6TFZv/B3MHR2jx4bDWW5mUyHPlnlYwTqc881+eCb29sSKmpEbc BLiznEW7xsPq7ZFmiWtjV9UpVb/+Zmw4jG/IkTZ/d X-Gm-Gg: AY/fxX5aUCSymiK/I9bcyyJYnHn8b+Tq8kl/USAbeJAexkQ5B69XvNIWBAlkotxs2is ce2VBUzSP65orNsm+G82wtkhDiWFvthvOvA87SjuoW8axk5DohN0DZ+cFK4U534wqNCV2GHCObk 9jRqqRHEnjINDFt9JSCv7SXWM38PcHzgJg/K5inXQBpr2skRAiCKK/f7bHO6tWOn3f+KsfHUukW DLmZC3qYl3HZyZfZoTJ1/sghRCexASNP9pivfIw0s2CHlV6Pmch6KaYw3CfgZAAYfgMmp6qwLO6 50ssyaEb4ZDYIRE= X-Google-Smtp-Source: AGHT+IHSlaXrardrx3TehZKNbB/dIpivlYMUbxJwLkujibtnhEouW4789w2CrAhTsFZceDX+jieUtOm59FGz3BECxHU= X-Received: by 2002:a05:7022:697:b0:119:e56b:98a5 with SMTP id a92af1059eb24-121f8b0db87mr11991741c88.12.1768033158199; Sat, 10 Jan 2026 00:19:18 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 10 Jan 2026 11:19:07 +0300 X-Gm-Features: AZwV_QhPob-csz8Zyay0ZEN_qj04Yj8zHyaRpB2nrv9f94kPEFWRgrrWviXQ0kQ Message-ID: Subject: [PHP-DEV] Analogue of Node.js Worker threads? To: internals internals Content-Type: multipart/alternative; boundary="000000000000587fef0648044cd5" From: pacha.shevaev@gmail.com (Pavel Shevaev) --000000000000587fef0648044cd5 Content-Type: text/plain; charset="UTF-8" Hi! Historically in my company PHP has been used as a CLI tool for project building purposes. For example for code generation, configs parsing and converting them into binary blobs, calling dotnet and go tools, etc. In general it's a cross platform 'make on steroids'. We are pretty much happy about it except one particular thing: convenient cross platform multi-threading. And we don't actually need a true multi-threading but rather something similar to Worker threads in Node.js. We tried using the AMPHP Parallel package but it wasn't stable enough for our needs (hangs or emits serialization errors for our workloads). And it also seems to be using a special 'ProcessWrapper.exe' (bundled with a composer package) to overcome some Window specific issues. Due to strict anti-virus policies we had to manually add an exception for it... So we ended up with some primitive wrappers around platform specific tools: for *nix we start background PHP processes with '&', for Windows - using 'powershell.exe Start-Process' for the same purpose. We pass data to and from these background processes using serialization and temporary files and while it works, well, it's pretty inconvenient and cumbersome. Out of curiosity I tried Node.js Worker threads and it just worked as expected for our sample loads both on *nix and Windows boxes. And there are some high-level wrappers over Worker threads like Piscina which simplify things even further: const worker = new Piscina({ filename: path.resolve(__dirname, "worker.js"), maxThreads: 32, maxQueue: "auto", }); const results = await Promise.all( files.map((file, idx) => worker.run([file])) ) I think PHP could benefit from having the similar 'multi-processing' support in the core. It seems like here's what Node.js does: 1) Spawns/stops worker threads 2) Passes serialized input/output between the worker manager and worker threads Since worker threads are fully isolated you can't directly access their internal data, there are no data races and there's no need for any synchronization primitives. I guess PHP could do the same even in non ZTS mode? And the aforementioned AMPHP could use this built-in Worker threads support without having to resort to any platform specific hacks providing a nice and clean interface. -- Best regards, Pavel --000000000000587fef0648044cd5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

Historically in my compa= ny PHP has been used as a CLI tool for project building purposes. For examp= le for code generation, configs parsing and converting them into binary blo= bs, calling dotnet and go tools, etc. In general it's a cross platform = 'make on steroids'.=C2=A0

We are pretty mu= ch happy about it except one particular thing: convenient cross platform mu= lti-threading. And we don't actually need a true multi-threading but ra= ther something similar to Worker threads in Node.js.

We tried using= the AMPHP Parallel package but it wasn't stable enough for our=C2=A0ne= eds (hangs or emits serialization errors for our=C2=A0workloads). And it al= so seems to be using a special 'ProcessWrapper.exe' (bundled with a= composer package) to overcome some Window specific=C2=A0issues. Due to str= ict anti-virus policies we had to manually add an exception for it... So we= ended up with some primitive wrappers around platform specific tools: for = *nix we start background PHP processes with '&', for Windows - = using 'powershell.exe Start-Process' for the same purpose. We pass = data to and from these background processes using serialization and tempora= ry=C2=A0files and while it works, well, it's pretty inconvenient and cu= mbersome.=C2=A0=C2=A0

Out=C2=A0of curiosity I tried Node.js Worker t= hreads and it just worked as expected for our sample loads both on *nix and= Windows boxes. And there are some high-level wrappers over Worker threads = like Piscina which simplify things even further:

=C2=A0 =C2=A0 const= worker =3D new Piscina({
=C2=A0 =C2=A0 =C2=A0 filename: path.resolve(__= dirname, "worker.js"),
=C2=A0 =C2=A0 =C2=A0 maxThreads: 32,=C2=A0 =C2=A0 =C2=A0 maxQueue: "auto",
=C2=A0 =C2=A0 });
<= br>=C2=A0 =C2=A0 const results =3D await Promise.all(
=C2=A0 =C2=A0 =C2= =A0 files.map((file, idx) =3D> worker.run([file]))
=C2=A0 =C2=A0 )
I think PHP could benefit from having the similar 'mult= i-processing' support in the core. It seems like here's what Node.j= s does:
1) Spawns/stops worker threads
2) Passes serialized input/out= put between the worker manager and worker threads

Since worker threa= ds are fully isolated you can't directly access their internal data, th= ere are no data races and there's no need for any synchronization primi= tives.

I guess PHP could do the same even in non ZTS mode? And the = aforementioned AMPHP could use this built-in Worker threads support without= having to resort to any platform specific hacks providing a nice and clean= interface.=C2=A0=C2=A0


--
Best regards, Pavel
--000000000000587fef0648044cd5--