Why it can't return the result before sleep function in PHP

Posted by Tianxz on Thu 20 May 2010 01:09 PM — 3 posts, 18,778 views.

#0
In the php, I want do a function after a trigger. The code like:

$world->Execute('hp');
sleep(4);
Task();

But the command hp doesn't display the result before the sleep time over. How can I do it?
USA #1
As you are sleeping, the program isn't awake to receive the MUD's response to the command.

There are easier ways of pausing scripts in Lua with coroutines, but I don't know of easy ways in PHP. You can get around it by doing things like calling DoAfter and giving it a timeout and the function to finish evaluating your code.
Australia Forum Administrator #2
Indeed.

Template:post=4956
Please see the forum thread: http://gammon.com.au/forum/?id=4956.


Although that mentions Lua, it also describes why sleeping doesn't work.