[php-src] PR #17838: Bring back isapiSAPI?

From: Date: Mon, 17 Feb 2025 11:40:08 +0000
Subject: [php-src] PR #17838: Bring back isapiSAPI?
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-30826@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/17838 Author: cmb69 20 years ago, the isapi SAPI was the most performant option to serve PHP with IIS (the only other option was classic CGI). However, ISAPI required ZTS builds, so [Microsoft and Zend coorperated to improve the situation](https://news.microsoft.com/2006/10/31/microsoft-and-zend-technologies-announce-technical-collaboration-to-improve-interoperability-of-php-on-the-windows-server-platform/), what led to FCGI being the most recommendable way to serve PHP with IIS (and later also NGinX). ISAPI fell from grace, [no longer shipped with the Windows binaries as of PHP 5.3.0](https://bugs.php.net/bug.php?id=48299), and [removed from the codebase as of PHP 7.0.0](https://wiki.php.net/rfc/removal_of_dead_sapis_and_exts#sapiisapi). During that long time a lot has changed: 1. ZTS builds became more stable, especially with PHP 7 changing the Linux configuration option from --enable-mainter-zts to --enable-zts. 2. The thread safe implementation has been greatly improved regarding performance with PHP 7; I couldn't find relevant documentation, but I believe what we have now is quite similar to https://wiki.php.net/rfc/tls (maybe @arnaud-lb can clarify). 3. Windows introduced ASLR, and while that was optional in early versions, it is pretty much enforced on contemporary Windows versions. Furthermore, it's more aggressive nowadays. So for a long time it is recommended to enable opcache.file_cache_fallback on Windows. 4. OPcache introduced some optimization which cannot be supported on Windows due to ASLR. To clarify: ASLR is not the real problem, but rather that Windows has no fork(2), and as such uses spawned processes which try to attach to OPcache shared memory. Now (3) is the actual problem I'm seeing here. If an FCGI worker process cannot re-attach to SHM, it falls back to using the file cache, which is barely faster than running without OPcache (at least according to some tests I made a couple of years ago). WinCache may alleviate this by caching the filecache in memory, but besides that WinCache has been abandoned by Microsoft (we have a barely maintained fork at https://github.com/php/pecl-caching-wincache), this isn't the real thing anyway (OPcache SHM can apply more optimizations). The clean solution to the ASLR/spawned processes on Windows would be to introduce something like FPM, but using threads instead of forked children. This would be a major undertaking, though, and since that this is known for years, nobody (to my knowledge) even attempted that. The next best solution is to use multi-threaded extensions to Webservers. We already have that for Apache (apache2handler) (although that still needs reattaching of the worker process; see #7865). For IIS, we had the isapi SAPI (which might also be [supported by Apache on Windows](https://httpd.apache.org/docs/2.4/mod/mod_isapi.html)), which can be run inside the IIS worker process (w3wp.exe). Therefore I've made the minimally required fixes (and threw out Zeus Webserver support), and some preliminary tests were satisfactory: it's basically working, and the performance is roughly on par with FCGI, and there is no more re-attaching to OPcache SHM, since there is only one process. One of the strongest points against running PHP inside the Webserver would be that any crash of a PHP thread would crash the Webserver; that appears to be basically solved, though, due to SEH support. Of course, there is still a lot to do to make the isapi SAPI ready for production, e .g. - [ ] support impersonation - [ ] support all HTTP status codes - [ ] proper (stress) testing (I haven't had a look into stresstest/, which may or may not be a good idea to have) - [ ] check out filter support Before going on, I would like to gauge opinions from the community whether it's even worth it. Maybe I'm missing some important arguments against isapi API. And of course, I'd be glad to get some help; just helping to test, reporting issues, and maybe doing some relevant benchmarks would be great! There has been an [interesting discussion](https://externals.io/message/65332) on the mailing list years ago. Seems like a good read.

« previous php.git-pulls (#30826) next »