Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122077 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30354 invoked from network); 31 Dec 2023 11:59:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2023 11:59:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1704024009; bh=enn8WMzK1LzueXUmZIq1YFcLV0vT1M/WMqExOxVCH9o=; h=Date:From:CC:Subject:In-Reply-To:References:From; b=VyhEVpf0T2/RgTi25uIfyBnbLeCcBerWcR4YxmwA6sVrkKer+ceyzNyoms8eEU0Un avJCtNbtZltHpUNCEl0MfA0ivkOi9t5G7+VD4EkEH/MurInLx5OgJzhplr8MWyjY/0 7PwTNqgQdxg+bPmC0a55NgA6VL/q7zG54SL+vy95hFTmwhfhAek+NyHe7nVzQ8M6PM dknTja+8hNbjWiKaif7ZhmwQ6EJeHeo8FgcTgez218yITF1s7tCQSdUL+NQbhSs3wK CNWvQv+3qIGfUyI/n0b4Dk8CImSlwUMIEDv/iTfcT82tAx2u2VsjZiuDklJM8to+7W MrSK6z5dz0kOA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC5B5180053 for ; Sun, 31 Dec 2023 04:00:08 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, MISSING_HEADERS,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-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ; Sun, 31 Dec 2023 04:00:08 -0800 (PST) Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33694bf8835so6553433f8f.3 for ; Sun, 31 Dec 2023 03:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704023978; x=1704628778; darn=lists.php.net; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:from:date:from:to:cc:subject:date :message-id:reply-to; bh=enn8WMzK1LzueXUmZIq1YFcLV0vT1M/WMqExOxVCH9o=; b=VfYSGn8qkFwntqKnC2pszB2pa008jUBjn5vp7PZLFXnZ8sESPBwWF9JR+U0mWHqAa1 NJDyaDfwRoFsBsXuzhwVncUFhIO2lOJBVwy+4uruExI/+x15OBAxo88ftatR0ZRNsOLQ YQxBMnUs2E3xk1xr4mjye54ZlxhINzozXnjzjzumPi+DKDrzft0AaSlVLwLsOvyQ4Ksy 1jEvpd0AVU9gJOfwmSOEAPOe5utdyEsaxJf/2FpBM14+RPCWEeJmsJb1zV+GiXjvBxj7 pB/ixJyUYxod8BzYYarPfcXdm33EmEBNnSP7rytAc/tFUMH5pOok4euuDUVZCLyn1Mcu zkHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704023978; x=1704628778; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=enn8WMzK1LzueXUmZIq1YFcLV0vT1M/WMqExOxVCH9o=; b=vbloITEXwcvSEoGdTz943XlCP8SZt4wXHC374gjs/VsP+rltDYrRlQp31J0cPJ7EwH wr+SB19L6FhMN9T6RNN2GWsD3PdvBjWlHSfthe7JPtvoTSLsAPoupdv5aebOyct7ysNN p3gw93N31/ZzLrZo7BxKKcKYzAgOExLiJqrFZqt10VZvqYBzpyxyOxQJWgyhYFUfyyKP OZqKJJbKuUCUiLU+GhETAolVCekSkArKom5k/DgV7tIBKGch8y3nAprq8QfTOj4KqZEG kt/UT4B/KYNm/QjxWyQDW1w5eDhRljpsxkSALE5RPJ9vVdpH2kMP8xR65McyOvYksuN4 8MgQ== X-Gm-Message-State: AOJu0YxejYnJw6PGRkNKfvacquy8HMbvYtMdCbRCYjOcR9/UXQ3b2FZY EQsper+9sOlr7OXFhbitBlYmBHevzJs= X-Google-Smtp-Source: AGHT+IHuBXEeMKJqUK4m5IqXYX2d9j0xs2SzmEEyhtG3dvzaUiwf9ysryk1nLecC/gLs37N6VP39tg== X-Received: by 2002:a5d:4144:0:b0:336:dddc:3956 with SMTP id c4-20020a5d4144000000b00336dddc3956mr4529016wrq.31.1704023978019; Sun, 31 Dec 2023 03:59:38 -0800 (PST) Received: from [127.0.0.1] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.gmail.com with ESMTPSA id f8-20020adffcc8000000b003366b500047sm23446678wrs.50.2023.12.31.03.59.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 31 Dec 2023 03:59:37 -0800 (PST) Date: Sun, 31 Dec 2023 11:59:33 +0000 CC: php internals User-Agent: K-9 Mail for Android In-Reply-To: References: <5060b986-2e5a-46e4-9c83-763e5b155e83@gmail.com> <6f7815b9-80cc-4e08-819a-49dca090116f@gmail.com> <7F63D301-1A46-49AA-9140-F64543E902C5@gmail.com> <8fb6672c-06e9-4f74-b2f2-cd1a265c75a5@app.fastmail.com> <96C28696-7C58-4018-84EB-69CF4189649B@gmail.com> Message-ID: <881CFFCD-220F-4A58-B5B9-C1FFFCE5E278@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC proposal: worker mode primitives for SAPIs From: rowan.collins@gmail.com (Rowan Tommins) On 31 December 2023 08:31:16 GMT, "K=C3=A9vin Dunglas" = wrote: >This new function is intended for SAPIs=2E Swoole was given as an example= of >worker mode, but it isn't a SAPI=2E AFAIK, it doesn't use the SAPI >infrastructure provided by PHP=2E >The scope of my proposal is only to provide a new feature in the SAPI >infrastructure to build worker modes to handle HTTP requests, not to deal >with non-SAPI engines=2E One of the advantages you suggested of your proposal is that users would h= ave a consistent way to write worker scripts=2E To achieve that, you want a= *design* that can be adopted by as many implementations as possible, regar= dless of how they implement it=2E Providing helper infrastructure for that = design is a secondary concern - as you admit, the actual code you're propos= ing to add is quite short=2E >That being said, I don't understand what would prevent Swoole from >implementing the proposed API Then one of us is missing something very fundamental=2E As I understand it= , Swoole's model is similar to that popularised by node=2Ejs: a single thre= ad processes multiple incoming requests concurrently, using asynchronous I/= O=2E For instance, a thread might run the following: 01 Request A received 02 Request A input validated 03 Request A sends async query to DB 04 Request A hands control to event loop while it awaits result 05 Request B received 06 Request B sends async HTTP call to some API 07 Request B awaits result 08 Request A resumed with DB result 09 Request A formats and returns response 10 Request A complete 11 Request B resumed 12 Request B fornats and returns response Each request has its own call stack, started by a different call to the re= gistered event handler, but any global state is shared between them - there= is no actual threading going on, so no partitioned memory=2E If requests are communicated by setting up superglobals, that will happen = at step 01 and again at step 05=2E If you try to read from them at step 09,= you would see them populated with information about request B, but you're = trying to handle request A=2E It would be possible to work around that by placing large warnings to user= s not to read superglobals after any async call - basically forcing them to= create scoped copies to pass around=2E But the worse problem is output: if= step 09 and step 12 both just use "echo", how do you track which output ne= eds to go to which network connection? You can't just set up an output buff= er, because that's global state shared by both call stacks=2E You have to p= ut *something* into the scope of the call stack - a callback to write outpu= t, an expected return value, etc=2E Asynchronous code ends up somewhat resembling functional programming: ever= ything you want to have side effects on needs to be passed around as parame= ters and return values, because the only thing isolated between requests is= local variable scope=2E =20 Regards, --=20 Rowan Tommins [IMSoP]