After reading the main PRISM php file, I checked the while loop and it seems that the while loop itself takes 1 second to process so I cannot use a timer that is a smaller interval.
Checking the difference between microtime at the start and end of the while loop shows that it takes 1 second.
I made 2 while loops (1 separate for the timers) and then realised both of them wouldn't run because one has to end before the next one begins...
I guess a solution would be to run it on a new thread which isn't possible on PHP afaik?
I had looked at how prism handles its timers previously, back when I was implementing something similar for pyinsim. Looking at the code in the PHPInSimMod.php updateSelectTimeout method I think I see what might be the cause of the bug:
if ($timeout < $sleepTime) $sleepTime = $timeout; } ?>
It seems that the expression $timeout < $sleepTime is comparing an int with a null, which will always evaluate false in PHP. I wasn't sure so I checked it on CodePad and my thinking appears to be correct.
Next in the same method there is this code:
<?php # If there are no timers set or the next timeout is more then a second away, set the Sleep to 1 & uSleep to NULL. if ($sleepTime == NULL OR $sleepTime >= 1) { # Must have a max delay of a second, otherwise there is no connection maintenance done. $sleep = 1; $uSleep = NULL; } ?>
It checks if the sleepTime is NULL, which it always is, then assigns the sleep variable a value of one second, which is what accounts for the constant one second stream_select timeout interval.
I think to fix the bug you would need to change the first problematic expression to something like the following:
I'm sure PRISM's main loop could be fixed up so it's faster. Edit: See DarkTimes' post above.
However, on the threads subject:
There are no threads in PHP, but you could come up with a hack using pcntl_fork - if you're on a POSIX compliant platform with pcntl enabled - or if you're on windows you could emulate it if you have the com stuff compiled into PHP (probably). It would be tricky to come up with something that works on both POSIX and Windows without needing to be programmed differently.
The main issue you'd have is that you'd need to communicate between your main process and your child process. If it's POSIX only you could use shared memory. If you want it cross platform PRISM would need another socket for communicating with the child processes and your child process would need to pass stuff to the PRISM process to send to LFS (unless you were using UDP, instead of TCP to talk to LFS).