473,396 Members | 2,013 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,396 software developers and data experts.

Need a small help in looping

i want to execute a script for every 10 seconds . and the loop is 10 minutes long.
I written the code like this but i got timeout warning. i have changed the execution time too in .ini file. please tell me what is wrong or give me a sample code for this:
Expand|Select|Wrap|Line Numbers
  1. $time = time();
  2. $timeafter10mins = $time+10*60;
  3. $result = mysql_query("select * from tbl_outbox where UniqueID like '%12345%'");
  4. while($time < $timeafter10mins)
  5. {
  6. while($row = mysql_fetch_array($result))
  7. {
  8. $uniqueid = $row['UniqueID'];
  9. $text = $row['message'];
  10. $from = $row['From_Mobile_number'];
  11. $dated = $row['dated'];
  12. }
  13. if($text!="" && stristr($text,$uniqueid))
  14. {
  15. $data = "<?xml version='1.0' ?>
  16. <SMS NO='$from'><SMStext>".$text."</SMStext><SMStime>".$dated."</SMStime></SMS>";
  17. $fh = fopen($uniqueid.'.xml', 'w'); 
  18. fwrite($fh, $data); 
  19. $xmlfile = $uniqueid.'.xml'
  20. ?>
  21. <script>window.location.href='<?=$xmlfile?>';</script><?
  22. exit();
  23. }
  24. $time = $time + 10;
  25. sleep($time);
  26.  
And also i wanted to delete the xml file after 10 mins.
Please give me a solution. Waiting for your response,
Thanks in advance,
Sridevi.
Jul 20 '08 #1
3 1064
pbmods
5,821 Expert 4TB
Heya, Sridevi.

sleep() does not sleep until a particular time; it sleeps for that many seconds. So your script is doing what you told it to do... run once and then wait for about 1.2 billion seconds... (http://php.net/sleep).

Try using cron or launchd instead.
Jul 20 '08 #2
Hi,
Thanks for your reply.
Can you please tell me how to use cron or launchd for my requirement?

Thanks,
Sridevi.

Heya, Sridevi.

sleep() does not sleep until a particular time; it sleeps for that many seconds. So your script is doing what you told it to do... run once and then wait for about 1.2 billion seconds... (http://php.net/sleep).

Try using cron or launchd instead.
Jul 21 '08 #3
TheServant
1,168 Expert 1GB
Cron Jobs

Basically the server will run a script for you every "x" number of seconds/minutes/hours/days. Have a read through some information off google and post back if you have any more questions.
Jul 22 '08 #4

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

Similar topics

17
by: madhav_a_kelkar | last post by:
i was browsing this problem: The following is a piece of C code, whose intention was to print a minus sign 20 times. But you can notice that, it doesn't work. #include <stdio.h> int main() {...
15
by: janhm | last post by:
Hello. I need to loop through a xml file finding a specific innerxml text and then ad the content to a treeview. For example. If the innerxml im searching for is "item001" then I want the...
1
by: Torben Laursen | last post by:
Hi I have a small generics class that I use to store values. The code is below. My problem is that if I use the class to store a string like: cItem<stringTest = new cItem<string>(" ", " ", " ");...
12
by: steven acer | last post by:
hello, i have a java app that constructs an xml from a specific file format and vice versa. i've been asked to convert it to c++, but im not an expert in c++, actually im mere beginner you can...
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
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
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.