HipHop for PHP
Haiping Zhou is project the HipHop PHP Compiler project. He is working for Facebook office in united state as Senior Software Engineer.
HipHop transform PHP code into C++ code. Then the resulting C++ code can be compiled into native binary executable code with a C++ compiler, like for instance GCC.
HipHop is developed for make efficient and fast of Facebook Server. Currently, over 90% of Facebook Web traffic is handle by PHP code which is compile by the HipHop Compiler.
HipHop is use for compile the PHP scripts into and executable programs that works as multi threaded Web Server. Multi threaded Web Server not only rum fasterbut makes more efficient use of server machine memory.
A multi-threaded Web server uses less memory because it uses a single memory pool for all simultaneous requests. This is different from using multi-process Web servers, like when you use Apache in pre-fork mode. This is the mode that most Apache based PHP sites use. In this mode, each request is handled by a separate OS process. Each process has its own memory pool.
The main problem of using multi-process Web servers is that when a process uses a large chunk of memory, that memory is not returned to the OS until the process exits. Even if subsequent requests handled by the same process do not need so much memory, the unused memory space cannot be reused by other processes that may be handling other simultaneous requests.
Apache can be forced to kill pre-forked processes once in a while in order to perform memory recycling, but there is always a waste of memory until the process exit happens.
The memory usage details are very important for sites that require more than one server machine. The memory used by the Web server processes determines how many simultaneous requests each Web server machine can handle.
For instance, if you have a Web server with 1GB of RAM and each PHP request takes 10MB of RAM, in theory it can handle less than 100 of simultaneous requests. If all programs running in the same machine use more than the physically available RAM, the OS has to use virtual memory and the machine starts slowing down, as it has to swap physical memory blocks with virtual memory segments in disk.
This is why a server that takes an excessive amount of simultaneous requests can be halted, causing what is known as a DOS: Denial Of Service. With Apache, you can use the configuration directive MaxClients to limit the number of simultaneous requests. That will prevent the machine to halt, but the Web server starts queuing incoming requests. This means that the requests may be handled with a great delay or even be ignored.
This is a matter that was previously discussed in a past article about the use of multi-threaded Web servers for handling high traffic. Notice that in that article it is recommended the use of multi-threaded Web servers only for serving static files like images, CSS and Javascript.
The new aspect of HipHop PHP compiler is that Facebook developers have made an effort to convert PHP extensions in such way that they are thread-safe. This means that they can run without crashing multi-threaded Web server programs, which is what the HipHop compiler generates.
Gee willkires, thats such a great post!
Im not wrtohy to be in the same forum. ROTFL
Thanks alot – your aneswr solved all my problems after several days struggling