473,800 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does sleep() work

code green
1,726 Recognized Expert Top Contributor
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 5094
pbmods
5,821 Recognized Expert Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
Heya, Code Green.

And a merry Chrismakwanzukk ah 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 Recognized Expert Top Contributor
A scheduled task runs a script stockAvailabilt y.php that produces a report of stock levels from a MySql database.
However, the beginning of stockAvailabilt y.php calls another script updateStockLeve l.php using exec().
updateStockLeve l updates the stock levels in the MySql DB from a MsSql DB.
I was worried that updateStockLeve l 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 Recognized Expert Expert
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 updateStockLeve l.php:

Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. unlink('/path/to/lockfile');
  5.  
And in stockAvailabili ty.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 Recognized Expert Top Contributor
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 updateStockLeve l is a standalone program that includes functions and classes that are common to stockAvailabili ty.
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
3280
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 with this problem. I am uncertain about what etiquette calls for, but more on that later. My Objective: I am trying to control the _VMWare Desktop_ application
2
5194
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 successfully printed on screen. Thanks a lot guys! ==========================================================
5
3852
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
2786
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 routine that loops through the file buffer: for (int i=0;i < _Buffer.length; i++) { // Code here
16
6738
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 any similar method. I want to make sure GC keeps up with the loop. My reasoning if Thread.Sleep(1000) is called; GC will take priority it do its work, right? GC.Collect(); GC.WaitForPendingFinalizers(); System.Threading.Thread.Sleep(1000);
0
1092
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 dynamic nature it's unclear to me how Shed Skin could know enough about the semantics of time.sleep to know whether or not it's broken on Win32. This suggests that to gain speedups it probably implements a more static language than Python. For...
17
3081
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 same problem seems to occur. Here the deal : when I run this piece of code, I expect all the memory allocated by the "Test" object to be freed but what I observe is that after the second sleep (after all the additions to the vector), the memory...
4
8849
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 windows service that converts MS Word Files into .PDF files and after that we want to zip the .PDF files. Our code: Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set...
0
1405
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 reproduces your problem is: <code> import signal
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10507
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.