On 2/21/08, Nathan Rixham <[EMAIL PROTECTED]> wrote: > Thankyou for taking the time to shed some light on the mater for me; I'd > missed the all vital "sharing resources" part of the concept, probably > because (if I'm correct in saying) php shares memory of > variables/classes/resources between parent and child processes until a > write occurs, at which point a new version of the aforementioned is > created. [please correct if wrong].
pcntl_fork() uses fork() call which is implemented in OS. Forked process is a copy of parent process, which means, that it occupies similiar amount of memory. Each time you "fork" your memory usage gets bigger > Would I therefore be correct in assuming the following: > > In PHP we can create mutli-process(tasking) applications that have most > of the benefits of multi-threaded applications and less bugs. > > I'm working on the premise that a processor can only run so fast, so > multithreading say 100k calculations would not speed up and application, > if anything it would add overhead, and slow it down. The only way to > speed up such an application would be to throw more hardware at the > problem (be it servers or processors). If your task is CPU-bound, you can't do much, but give it more hadrware. (we are not talking about optimization of algorithms here) > Meaning that the only time multi-process/multi-threading would have any > positive bearing on an application would be when dealing with things > such as external resources, due to the slower access times of these > external resources we find threads/processes "waiting" for the resource > to be usable (fully downloaded/opened) - in such a situation > multi-threading has it's distinct advantages. > > However forking an app (?multi-process) can already achieve the same > results, the only difference being that we may have a few duplicate > classes/variables around the application doing it this way (subject to > us not taking the time to define all "shared" resources in the parent > process. Multithreading can be dramatially good for memory-bound tasks. It is possible to say (although, this is oversimplification), that threads are "light processes". They allow to execute a lot of parallel tasks with less overhead > If I'm correct in all of the above, then I'd personally think that we > don't need multithreading in PHP, however a neat(er) predefined method > of interprocess communication would be beneficial. -- Alexey Zakhlestin http://blog.milkfarmsoft.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php