Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116969 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83988 invoked from network); 1 Feb 2022 19:12:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2022 19:12:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 000201804D9 for ; Tue, 1 Feb 2022 12:26:31 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 1 Feb 2022 12:26:31 -0800 (PST) Received: by mail-ed1-f49.google.com with SMTP id r10so37156074edt.1 for ; Tue, 01 Feb 2022 12:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B3qgwYQquMK8bS+apfoYc7/9UDlhD5LKnmGc5t7olfA=; b=lq2hSHEIOte0cgMJBoFBuOBOLqR0ekERygJtKknHox39TRn3/StwIerGy5SRPesKoM isLz3AM6SnLwBrS9JTJ94D3sV0O8S8sUOzQpEsIbdK0v/sUaQHSheE/WGDpAFCVyAEQw WzUBU/TBeBYEVJeBkZ1k6B9E07FutGKUs6UKwcB9CbiuVQk6d/61u+WXgfW+WgLQ+5+h MQRTSbQ0Dmsr4JmRobHiuAnjsPl39MMa9LKhEPD4xtYGy0f+NtyAXzcmt+lUdAJemT/q lsECoImr1quzK+3ZhtBj2bzW6RMJJmt4hUWHbnP7Dj4Ax9WmkMctefLM/NyQzWuYucmw iUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B3qgwYQquMK8bS+apfoYc7/9UDlhD5LKnmGc5t7olfA=; b=ai+PKNVjci1m7LvDV6nc6gBaFPx1blJlCGbiuLuypmEdi3x9QlCBL3kBUAeDH/kD1e iPpMX7PuO10N6uVvmlKAYc4b2Z0ERdbbevNQMxsbMoFxclYlhmbFH1VZztQKhZZmqmaY /ztyQ4zHOI0Ttb3P1oniJjLXW7HUdbV8Pp/xz9qsoXqU2gbVfCut+SViKUYdpN8VXl8H TlZEpN0DsddtI+r302elX8o+1YyJVb0W4nI+8kW+3k+mhNf7Z6u5gB87LrI9gueH4sgE WYioBHaj1g6TVSYKweIgfNfU4IVgOVHDsmjlsRv1RylLGQ9xVmt+++oCSLKK5PzmOhQt tZRA== X-Gm-Message-State: AOAM53152jDWXQPsCQm73egDg/tLhdQW65hEXkNbKLVeraX5BFJka0YE cel7av8n0pohCLgVFu3A0jUbdlmDZ/cpvMp+/ACh0D3U X-Google-Smtp-Source: ABdhPJyC4Q/IzDRjoEb6OwQ/Ic4KRWBmG9H6fgv3u8ywj9O+hTkaiY1OA2+TnE9K+02xc9y6YI6LXM2gu+sVXw5xZ6o= X-Received: by 2002:a05:6402:4415:: with SMTP id y21mr26820600eda.162.1643747189851; Tue, 01 Feb 2022 12:26:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 1 Feb 2022 21:26:13 +0100 Message-ID: To: as@php.net Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000005a099405d6fab791" Subject: Re: [PHP-DEV] [RFC] Embedding multiple PHP engines in a single thread From: nikita.ppv@gmail.com (Nikita Popov) --0000000000005a099405d6fab791 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 1, 2022 at 3:36 AM wrote: > Hello internals, > > As you know, the PHP codebase makes heavy use of global variables. In ZTS > builds, access to these globals are cleverly mapped to thread local storage > via macros. To my knowledge, the limitation here is that there's no way to > run multiple PHP engines in a single thread. (Please let me know if I'm > missing something.) > > Naturally this is an extremely slim corner case. It would however unlock > some interesting things like user-land zend_extensions and SAPIs without > spawning threads needlessly. It would also enable one to build a > coroutine-based SAPI[1]. > > I'm curious if there's been any previous discussion around this, or if > anyone has general feedback before I take a shot at this. > > My rough idea is to modify TSRM to support multiple > `tsrm_tls_entry.storage` per thread, keyed by some caller-supplied id. > Currently a thread-safe resource is accessed like > `thread[thread_id].storage[resource_id]`. In my idea it would be > `thread[thread_id].storage[storage_id][resource_id]` with some API function > to push/pop `storage_id`. Any thoughts on that approach? > > Support for non-ZTS builds would be rad but would require much larger code > changes. > > Feedback appreciated. > > Thank you, > > Adam > > [1] for example, to call into PHP concurrently from Go's green-threads > (which may share a single OS thread) > In places we also use real thread-local storage (ZEND_TLS) -- actually, this is the preferred method to manage global state if it is possible. Nowadays TSRM exists essentially only to work around deficiencies in cross-DLL TLS support on Windows. I don't think your scheme could extend to those cases. I'm not really convinced that it's worthwhile to invest effort in this directly. Regards, Nikita --0000000000005a099405d6fab791--