Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28285 invoked from network); 1 Feb 2022 01:21:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2022 01:21:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DB92B180381 for ; Mon, 31 Jan 2022 18:35:36 -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=1.3 required=5.0 tests=BAYES_50, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, 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-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Mon, 31 Jan 2022 18:35:33 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id c15so22051785ljf.11 for ; Mon, 31 Jan 2022 18:35:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=d//CZFfWgCmekGIx4Z9yVBP4FMaYLGn0UyEvcb/QlHE=; b=eb2hrtjMALfTap8Wzu6Bhz5idIKyVxfUv63PZl/iVjjsPholU/i3YP3KcP0ciBR/Zn kVBD/DbXKwjPCzUN1iM1gADTxVkmQZNDWrPsN8JgGYUENZ7DLfkFDdoEe1Qi2i+tqMEc heYPOGNLowz6upOphj+Z2qUeDTK1Up3e8+EEcvBvmhlggDBWTEE1w6JSL48IFLugKizb Zs0WWropk7zJpefwFzL63/Qo4YBuPticigOXk+mYBPEsdtoCFs/XGXxg6Joe1m39f/Io gv63b+fcvZ/qW6xjrfbhYeP49P+i/UTd0gyIpwDggc/A7bNXAtS1To7aaXGc8aX/wroB 7OlQ== X-Gm-Message-State: AOAM530RM37n17sL7Y3RlWfF0uggUyCZRA/QymbG3IClcRj2saYQn4oe geQaSixbqWvUrkQ/rDcG1H+UMwa+R1mNXw== X-Google-Smtp-Source: ABdhPJz83qGD4Zg7iKk9TX/TKSLCK7oOvo0pcEDfVebzRSkCgTjg0ZkSnARi/9tM57QJyeVbfXOOfw== X-Received: by 2002:a05:651c:1543:: with SMTP id y3mr9256935ljp.152.1643682931585; Mon, 31 Jan 2022 18:35:31 -0800 (PST) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by smtp.gmail.com with ESMTPSA id z21sm3872639lfh.134.2022.01.31.18.35.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jan 2022 18:35:31 -0800 (PST) Received: by mail-lj1-f170.google.com with SMTP id e9so22118036ljq.1 for ; Mon, 31 Jan 2022 18:35:31 -0800 (PST) X-Received: by 2002:a05:651c:150b:: with SMTP id e11mr12302299ljf.283.1643682931069; Mon, 31 Jan 2022 18:35:31 -0800 (PST) MIME-Version: 1.0 Reply-To: as@php.net Date: Mon, 31 Jan 2022 21:35:15 -0500 X-Gmail-Original-Message-ID: Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000003ad88f05d6ebc1b7" Subject: [RFC] Embedding multiple PHP engines in a single thread From: as@php.net --0000000000003ad88f05d6ebc1b7 Content-Type: text/plain; charset="UTF-8" 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) --0000000000003ad88f05d6ebc1b7--