Skilled Illusionist
- Joined
- Mar 26, 2013
- Messages
- 371
- Reaction score
- 280
Isn't this like the 4th thread of BloonPHP?
socket_select($changed,$write,$except,NULL);
foreach($changed as $socket){
if($socket==$master){
}else{
Since it's only going to be the first in the array, I think it would be better to do
socket_select($changed,$write,$except,NULL);
if($changed[0] == $master){
master code
unset($changed[0]);
}
foreach($changed as $socket){
normal code
Otherwise you'd have a if/else 500 times (if you have 500 online users) that's not necessary
PS: For is slightly faster than foreach
I never understood why people would make an emulator in PHP. Isn't something like C#/Java/C++/whatever much better?
Well, good luck with it.
Well it isn't.
You must be registered to see links You must be registered to see links You must be registered to see links
...and the list goes on
Did you pull that fact from your arse?
I never said that, I said only the first item in the array has the potential to be the master, so checking on all of them (can be 500 if you have that many connections) would waste a lot of if/else checks
Another tip: If you're aiming for a high speed you should squeeze out every bit of performance you can and use as less overhead as possible. Use static so the pointer to the values doesn't have to be passed, pass strings and arrays as a pointer so they're not copied in memory, send buffers ASAP so you can reuse the memory and not get 1000 of buffers laying around. Also, you should find the best way to emulate "async" in PHP so you can send tasked packets to sockets that are still waiting for a potential send/receive. That was the part where I gave up because my implementation (async with suppressed socket async -> bool (false) means no data -> check for tasks). By that I mean for example a working pathfinder.
I hope your project goes well, if it does we might finally get a good working emulator across all OSes
PS: For is slightly faster than foreachNVM THIS
I use PHP pthreads for multi-threading (just pathfinder for now) and I will use PHP APC for shared memory between all threads.
azaidi : I don't need emulate "async", I use real posix multithreading with pthreads
The APC module is deprecated...
You have other idea for sharedmemory between 2 threads ? :ehh: