The biggest difference between Java web server and PHP is that PHP does not have its own embedded web server. (Well, new versions, but they should only be for testing, this is not a ready-made web server). PHP itself is basically one executable file that reads in the source code file of the PHP code and interprets / executes the commands written on this file. It. This PHP architecture in a nutshell.
This executable supports the default API, which can call the custom field PHP code, and extensions can be added to provide more APIs. These extensions are usually written in C and compiled with the PHP executable during installation. Some extensions can only be added by recompiling PHP with additional flags, others can be compiled against installing PHP and activated via the configuration file after the fact. PHP offers the PEAR and PECL side projects as an attempt to standardize and simplify such installations after the fact. Userland PHP code often also includes additional third-party libraries that are simply written in PHP code. The advantage of C-extensions is their speed of execution and access to low-level system access, the advantage of user code libraries is their trivial inclusion. If you manage your own PHP installation, it is often simple enough to add new PHP extensions; however, on a very popular model with a shared host, tension often arises between what the host wants to install and what the developer needs.
In practice, a web service written in PHP runs on a third-party web server, very often Apache that processes any incoming requests and calls the PHP interpreter with the requested PHP source file as an argument and then provides any output for this, go to HTTP to the customer. It also means that a persistent PHP process does not work continuously with a persistent state, as is usually the case in Java, but each request is processed by starting and then flushing a new instance of PHP.
Although Java simply stores persistent data in memory, the persistence of data between requests in PHP is handled using a number of methods such as memcache, sessions, databases, files, etc .; depending on the specific needs of the situation. PHP has operation code cache add-ons, such as Java bytecode, so PHP does not have to repeat the same parsing and compilation process each time it executes the same file.
Keep in mind that itβs possible to write a permanent PHP program that works just like Java, itβs just not the default PHP modus operandi. Personally, I am a fan of writing workers for specific tasks in Gearman or ZMQ that work hard and have some ephemeral scripts running on a web server, like "frontend", which delegate the work to these workers as needed.
If this sounds like a typical PHP application, it is much more like gluing together a few disparate components, you would be right. Java is pretty autonomous, with the exception of external products such as RDBMS servers. PHP, on the other hand, often tends to rely on a bunch of third-party products; which can work to your advantage in the sense that you can use best-in-class products for specific tasks, but also requires large costs for working with various systems.