oceans Posted May 17, 2007 Share Posted May 17, 2007 Dear Friend, I wish to insert “usleep()” in a while loop. “ While(not right) { Usleep(100); } Ok it is right, do something, bla bla bla … “ I was advised usleep() will soak up server resource. How can I improve or use an alternative. I admit I have done such operation in VB, I had such problem, and I later developed my own sleep function call which used almost no resource. But I am not sure if usleep() is efficient, have you experienced this? Any comment. Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/ Share on other sites More sharing options...
trq Posted May 17, 2007 Share Posted May 17, 2007 The question is why? Why would you need this in a web environment? Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/#findComment-255055 Share on other sites More sharing options...
hvle Posted May 17, 2007 Share Posted May 17, 2007 Interesting! I have just test it out on my system. usleep(50000000); // sleep for 50 seconds and watch the system resource and performance. I found no resource being used. CPU idle is 100%. Memory used does not change. I guest it is safe-to-use function. os: xp pro php version: 5 Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/#findComment-255056 Share on other sites More sharing options...
trq Posted May 17, 2007 Share Posted May 17, 2007 Same with sleep, still doesn't answer my question. I just can't see a need for it. Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/#findComment-255057 Share on other sites More sharing options...
hvle Posted May 17, 2007 Share Posted May 17, 2007 I remembered one time when I tried to test the server time out value, I think it was file upload time out. Instead of dumping out a big upload file, I set the script to wait 15.1 minutes (upload time out is set at 15). But you right, I never encounter a situation where I must delay the script execution. Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/#findComment-255060 Share on other sites More sharing options...
oceans Posted May 17, 2007 Author Share Posted May 17, 2007 OK Friends, I will use this to prevent multi threaded operations. In a very unlikely event (1/infinity) probability, if one global function gets called by B before A has done with the function, use usleep for B to wait till A is done. Link to comment https://forums.phpfreaks.com/topic/51771-help-me-please/#findComment-255070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.