Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101996 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27676 invoked from network); 22 Mar 2018 13:08:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2018 13:08:18 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 84.19.169.162 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 84.19.169.162 mail.experimentalworks.net Received: from [84.19.169.162] ([84.19.169.162:58618] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/A2-03694-0CAA3BA5 for ; Thu, 22 Mar 2018 08:08:16 -0500 Received: from [192.168.2.125] (p508EB8AE.dip0.t-ipconnect.de [80.142.184.174]) by mail.experimentalworks.net (Postfix) with ESMTPSA id 5E1137279D; Thu, 22 Mar 2018 14:08:13 +0100 (CET) Message-ID: <1521724088.2237.21.camel@schlueters.de> To: Alice Wonder , internals@lists.php.net Date: Thu, 22 Mar 2018 14:08:08 +0100 In-Reply-To: <360598cf-f723-1279-0a95-3c5055447fe8@librelamp.com> References: <421fae6f-d6ba-1990-d3d8-9ac236313cea@evermeet.cx> <360598cf-f723-1279-0a95-3c5055447fe8@librelamp.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] what's the official position on apache threaded environments From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Mi, 2018-03-21 at 22:52 -0700, Alice Wonder wrote: > Is there a list somewhere of what the specific issues with using zts > in multi-threaded apache are? What modules have known issues? > > I haven't found it. PHP itself should be thread-safe, if there are bugs inside PHP itself we try to fix them. However: PHP links to tons of external libraries, some of them might not be fully thread-safe or make assumptions. An example for such assumptions, aside from obvious memory access issues, is around the current working directory: In a threaded environment all parallel handled requests are in the same process and there can be only one "current working dir" (cwd) per process. We have the VitualCWD to mitigate, but that doesn't control what happens inside an external libraries code. A list for that doesn't exist as verifying this is hard. Most mainstream things should be thread-safe, while even some C standard library features we use sometimes aren't thread-safe (i.e.  due to use of the global "errno" for returning error codes, protecting these needs tons of locks which can limit scalability a lot ... if there are thread-safe/re-entrable versions of such library calls exist we should use them, not using them is a bug on our side, maybe since the thread- safe API is "new" compared to our implementation or too system- specific) On the more philosophical reasoning PHP tries to isolate requests from each other. Whatever happens in one request should not impact the other requests. By relying on the operating system's process isolation we gain a boundary. A known example where this fails are some forms of recursion where we still reach stack overflows (way less situations than in the past, but still) On stackoverflow the operating system will terminate the process. In a per-process model this impacts only the failing request, in a threaded model hits all parallel threads. (and eventually the complete server, whereas in a per-process model one always has a super process watching and restating children) There had been attempts at different times by different folks Zend, Sun Microsystems, Microsoft etc. to improve this, but it never got mainstream trust. A bit different is having threads inside a single script run, there also has some work been done (-> pthreads) but often people decide to offload longer running tasks to external systems (microservices?) instead of building a single large system. So that also didn't go mainstream (while there still are use cases) johannes