On 24-01-2020 10:29, Robert Hickman wrote: > PHP is pretty unusual in comparison to most web platforms nowadays as it > runs each request in an isolated process. Web development in other > languages is instead based around a long lived set of processes, which > serve multiple requests.
The shared-nothing architecture of PHP is the very thing that makes it simple and robust for web development by default. I do a lot of Python web development as well and the fact that it implicitly shares state between handling multiple requests has bitten me more than once. The same is true for writing multi-threaded code. This is very tricky business in most programming languages. PHP extension 'parallel' by Joe Watkins leverages the shared-nothing architecture of PHP to make writing multi-threaded code simpler and more robust. Very clever. > That model has advantages in that it is very easy to cache data in process, > and should be simpler in theory to get good performance as all code can be > loaded into memory once during startup. Autoloading therefore goes away. Yes, getting better performance is easier but writing robust code becomes harder. > There are userland implementations like PHP-PM, but I think it good to have > an official way of running code in this way in php 8. I'm not sure what you mean by an 'official way'. What is the problem with using one of the userland implementations? One thing I can imagine PHP could offer in this area is exposing the existing internal mechanism to mark data as persistent. This mechanism is used by extensions to offer persistent network connections for instance. It could be used to implement a language feature to allow sharing specific state between requests in an explicit way. When using an event loop based framework everything is shared implicitly. Now suppose that we could declare a static variable like this: static persistent $var; When the request ends the PHP interpreter data is cleared to handle the next request. Only the data that is explicitly marked as persistent survives the request and is available in the next. This would allow retaining the current shared-nothing architecture while offering the means to break the rules in a well defined way. Regards, Dik Takken -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php