Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Mutli-process PHP applications (e.g. an application that forks itself using <code>pcntl_fork()</code>) are inherently inefficient in terms of memory because each child process loads an entire copy of the php executable into memory. This can easily equate to 10 MB of memory per process or more (depending on the application). Compiling extensions as shared libraries, in theory, should reduce the memory footprint, but I have had limited success with this (actually, my attempts at this made the memory usage worse for some unknown reason).</p> <p>A better approach is to use multi-threading. In this approach, the application resides in a single process, but multiple actions can be performed *concurrently** in separate threads (i.e. multi-tasking). Traditionally PHP has not been ideal for multi-threaded applications, but recently some new extensions have made multi-threading in PHP more feasible. See for example, <a href="https://stackoverflow.com/a/12487840/896660">this answer</a> to a question about multithreading in PHP (whose accepted answer is rather outdated).</p> <p>For the above problem, I plan to refactor my application into a multi-theaded one using <a href="https://github.com/krakjoe/pthreads" rel="nofollow noreferrer">pthreads</a>. This requires a significant amount of modifications, but it will (hopefully) result in a much more efficient overall architecture for the application. I will update this answer as I proceed and offer some re-factoring examples for anyone else who would like to do something similar. Others feel free to provide feedback and also update this answer with code examples!</p> <p>*Footnote about concurrence: Unless one has a multi-core machine, the actions will not actually be performed <em>concurrently</em>. But they will be scheduled to run on the CPU in different small time slices. From the user perspective, they will appear to run concurrently.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload