i want to make a short not that many think multi-tasking is not working as expected, but actualy this is expected.
multi-tasking / multi-treading does not run paralel as many think. its actualy a constant switching between 2 or more treads. this has to do with the fact there is only 1 cpu. and 1 cpu can only execute one command at the time. every os works this way, linux, windows, even mac.
the only thing here is that os are written in C++ and PHP first has to be translated into C++ calls before executed. thats why PHP will never be as fast as C++ code and thus you will note the switching as a delay. thinking it does not run paralel but at this very moment your os is switching between diffrent treads with about 1 million switches every seconds where php may only achief 40.000 a second.
so when designing some multi-tasking system you must expect a system that constantly switches form task about every 20 tick for example. this will give the idea that the system is executing multiple thinks at the same time while actualy switching between them every 20 ticks.
hope this clears things up for some people trying to design a multi-treaded / multi-tasking system just as me.
most important: keep the switching code to a minimum. this is executed as wel between every switching treads.