473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How does sleep() work

code green
1,726 Expert 1GB
Does sleep hand temporary control back to the Operating System
or does it still demand the same resources as when the script is running?
Does it work the same way as VB doEvents().
I am updating data from mssql database to MySql on an overnight scheduled task.
I would like to wait a few secs to ensure the data has gone in,
then run a confidence check on the new data, emailing me of any problems.
Dec 6 '07 #1
6 5077
pbmods
5,821 Expert 4TB
Heya, Code Green.

PHP's sleep() function essentially runs through an idle loop for n seconds. It doesn't release any memory, but it should not increase CPU load significantly.
Dec 23 '07 #2
code green
1,726 Expert 1GB
Merry Christmas pbmods.
Thanks. That is all I wanted to know.
sleep() will hang the PHP script but still use the same resources.
Nevertheless a query on a database will continue to execute within the DB engine.
Dec 24 '07 #3
pbmods
5,821 Expert 4TB
Heya, Code Green.

And a merry Chrismakwanzukkah to you as well.

sleep() will hang the PHP script but still use the same resources.
Nevertheless a query on a database will continue to execute within the DB engine.
This is correct, however you'll have to help me understand your situation, because you shouldn't need to force PHP to wait until a DB query finishes executing. PHP will always wait for a DB query to return when you use mysql_query(), et al.
Dec 24 '07 #4
code green
1,726 Expert 1GB
A scheduled task runs a script stockAvailabilty.php that produces a report of stock levels from a MySql database.
However, the beginning of stockAvailabilty.php calls another script updateStockLevel.php using exec().
updateStockLevel updates the stock levels in the MySql DB from a MsSql DB.
I was worried that updateStockLevel may still be running because it has been called by exec(),
while the first script compiles its report.
Or even the MySql engine was still updating.
My understanding of exec() is that it can run in the background.
So in my situation I have something like a multi-thread.
Dec 27 '07 #5
pbmods
5,821 Expert 4TB
Heya, Code Green.

I'm sure there is a good reason for this, but why exec() a PHP script rather than include() it?

I suppose what you could do is create a lockfile. Add something like this to the bottom of updateStockLevel.php:

Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. unlink('/path/to/lockfile');
  5.  
And in stockAvailability.php:
Expand|Select|Wrap|Line Numbers
  1. touch('/path/to/lockfile');
  2. exec('php /path/to/updateStockLevel.php');
  3.  
  4. while( file_exists('/path/to/lockfile') )
  5. {
  6.     sleep(1);
  7. }
  8.  
Dec 30 '07 #6
code green
1,726 Expert 1GB
Thanks, pbmods I will study that technique.
I'm sure there is a good reason for this, but why exec() a PHP script rather than include() it?
Well updateStockLevel is a standalone program that includes functions and classes that are common to stockAvailability.
So I had function/ class redeclaration problems.
Jan 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
2
by: JosephWu | last post by:
Hi all. I have the following code and the 1000 numbers has stored before calling fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but if i delete sleep(1) ,the number will...
5
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
16
by: LP | last post by:
Hi, Considering code below. Will it make GC to actually collect. One application creates new instances of a class from 3rd party assembly in a loop (it has to). That class doesn't have .Dispose or...
0
by: skip | last post by:
I just noticed the announcement of Shed Skin 0.0.16 on Freshmeat with this (partial) change announcement: Changes: frozenset was added. time.sleep now works on Win32. Given Python's highly...
17
by: christophe.chazeau | last post by:
Hi, I have a problem with a really simple chunk of code which should work but does obviously does not. This chunk of code is just a POC aimed at finding a bug in a larger project in which the...
4
by: Steven De Smet | last post by:
Hello, This is my first post. I searched on the internet for answers but I was unable to solve my problem. So I hope that you guy's can help me with my VB.NET problem I tried to create a...
0
by: Tim Golden | last post by:
Lowell Alleman wrote: Well you've certainly picked a ticklish area to run into problems with ;). First, forget about the threading aspects for the moment. AFAICT the smallest program which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.