PHP - How Long Can A Program Sleep()
Similar TutorialsIn one of my servers when ever I call sleep or usleep functions my script sleeps and never wakes up, Any suggestion on what can cause the issue? my php -v output: Code: [Select] PHP 5.2.17 (cli) (built: Jan 24 2012 20:49:48) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with the ionCube PHP Loader v4.0.12, Copyright (c) 2002-2011, by ionCube Ltd. I have this code: <html> <body> <?php echo date('h:i:s'), "<br>"; sleep(5); echo date('h:i:s'), "<br>"; echo "Your Pizza: ", $_POST["Pizza"]; echo " Has Been Sent To The Counter"; ?> </body> </html> which gives me this result:
07:41:06 I can't seem to get the page to sleep at all.
My intention is to achieve this a page that will display the message above for 5 seconds then run a relocation to the main page. but for now just making the page sleep would be of benefit.
any help would be appreciated. I am a beginner so I am expecting this to be something simple i have missed.
For example with an IDE to run a program is there a way to put some code in the path and let it tell me where it came from like a referral? $ref = $_SERVER['HTTP_REFERER']; echo("$ref<br>"; Result: https://www.mydomain.com/wp-admin/admin.php?page=lambo As you can clearly see the page that we have entered the code in is referred by the URL here. It tells me that it was last at a word press page /wp-admin/admin-php and I can go to that page and it will be the last page it was at.. So bottom line then if i add this code to the admin page and click the same button i had before.. it will tell me the file that called out the admin page. Baslcaly I am looking for ideas on how to track the page i am now all the way back to the page with the button on it and all intermediate pages that it passes thru to get to the final destination. It seems that to succesfully troubleshoot a fault is to follow the path of the entire job and see if any breaks... Any thoughts or suggestions on how to best do this would greatly be appreciated.
I have a download page for my website and I tried using sleep to delay before the user can download an item. Right now I am using javascript to display a count down and the download link is in a hidden div and I wanted to have a time in php when the user goes to the page the timer starts and then echos the download link instead it being visible in the source code. <script> <!-- // var milisec=0 var seconds=30 document.counter.d2.value="30" function display(){ if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1){ milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",100) } display() --> </script> <div id="hid" style="visibility:hidden"><center><a href="upload/'.$row[4].'/'.$row[1].'"><img src="images/download.png" width="200" height="55" border="0" /></a></center></div> <script type="text/javascript"> function showIt() { document.getElementById("hid").style.visibility = "visible"; } setTimeout("showIt()", 30000); // after 1 sec </script> Well PHP manual says that the script execution will be delayed by $x seconds if you write a codes like this: Code: [Select] $x = 5; //5 secs sleep($x); Now I have this script in which I write the four lines to the screen one by one, each should be delayed by 5 secs after the last line is output to the screen. It does not work out at all... Code: [Select] echo "Update setting 1:"; sleep(5); echo "Success! <br>Updating setting 2"; sleep(5); echo "Success! <br>Updating setting 3"; sleep(5); echo "Success! <br>Updating setting 4"; Instead, the entire script execution is delayed by 15 secs, with all four lines output at the same time. Why is this happening? Is there a way to fix it? Please help... Hi, I am trying to loop a script every 10 seconds but am getting the following error: Fatal error: Maximum execution time of 60 seconds exceeded Part of the code is: <?php while (1) { echo "hello"; sleep(10); ob_flush; flush(); } ?> I have put echo "hello" just to test before adding the script. Is there a correct way to do this loop? also running this the page struggles and says it is still loading. When you use the sleep function in a script, will the script resume from that exact spot? I guess what I need to know is will it break an upload to MySql database of a csv file or will the whole file be uploaded? Thank All Hi All, I'm new to PHP and I'm probably making a fundamental mistake somewhere, however, enough time wasted, I thought you might be able to shed some light on my problem. I basically have a php script running with nginx and fast_cgi. The whole script is just a large switch statement that does some matching against the request strings and returns a template rendered by Tenjin. It all works fine and it's quite performant based on a simple curl-loader test. The simple performance figures are taken from curl-loader and show 400 CAPS (Call Attempts Per Second). The test is 200 clients requesting the same url for 100 cycles. The problem arises when I introduce a "sleep" into the php code for 150 milliseconds, which is my basic idea of introducing latency to the system. The performance for the same test of 200 clients * 100 cycles produces 55 CAPS which is a huge drop in performance based on 150 millisecond delay. The sleep method used is "usleep" and I've also tried "time_nanosleep". I know there's not a huge amount of info there but based on performance figures above, is there something fundamental/trivial I'm missing or doing??? Are there any known issues with the sleep methods??? I've tried setting 'set_time_limit(0)' before the sleep call but that didn't help. Any advice you can offer is greatly appreciated.. I want the login script to echo out a statement, and then after 5 seconds (if the user hasn't clicked the link manually) I want it to redirect with the header redirect. I'm using the sleep function for the delay of the redirect. Here's the concerned portion of the login script: // check to see if the INPUT DATA matches the DATABASE COLUMNS! if ($nickname == $dbuser_name && sha1($password) == $dbuser_password) { // set a session after login $_SESSION['user_name'] = $dbuser_name; $_SESSION['user_id'] = $dbuser_id; echo "<center>You're logged in! <a href='01.php'>Click here</a> to go to the main page.</center>"; sleep(5); // seconds to wait header ('Location: 01.php'); // password incorrect error message } else { echo "<center>Incorrect password!</center>"; } But the echo statement never gets printed out, any idea why it gets swallowed by the sleep function? Hi All, I am trying to call a javascript pop-up window via a link by echoing out the html via php but keep getting parse errors: Parse error: syntax error, unexpected ')', expecting ',' or ';' Here is the code in question: Code: [Select] echo "<td class=\"today\"> <a href=\"javascript:statusWindow('status.php?month=".$month."&day=".$day."&year=$year');\">"$day_num</a> </td>\n"; And here is the javascript function: Code: [Select] <script type="text/javascript"> function statusWindow(url){ status_popupWin = window.open(url, 'status', 'resizable=yes, scrollbars=yes, toolbar=no,width=400,height=400'); status_popupWin.opener = self; } </script> Any help is appreciated. Thanks, kaiman I would like to apply some addition functionality to a form which add news records into the database. Basicaly what i want is similar to what this forum does with the [ code ] [ /code ] but what i want for the user to be able to add [ quote ] [ /quote ] and when the post is viewed then that specific area of the acticle body will be formated diffrently. I hope this makes sence. Hey Folks This is a major long shot but is their a way that i can use php to upload one mp3 file and one doc file, then get the php script to place the mp3 file in one folder but also copy the mp3 file and make it into a zip file and place it into another folder as well as also make another copy of the mp3 file pair it with the doc file and make it into another zip file in yet another folder mp3->---------------------------->--mp3----------------->----mp3 into zip-------->--mp3 + doc into zip &---- > --Uploaded via php----->--placed in folder a--->----placed in folder b--->--placed in folder c doc-->---------------------------->--copied--------------->----mp3 copied--------->-- But thier is a catch the host i am using didn't activate ZipArchive() function so need a diferent way to make the zip file. Any Ideas people? because i have been pulling my hair out at this one please help Phil Guys, why the following mysql stored procedure taking much more time comparing with firebird one?
1. MySQL stored procedure
CREATE DEFINER=`lxc`@`::1` PROCEDURE `insertData`(IN it INT) BEGIN declare i int Default 0; declare str char(4); declare p_hash int; myloop: loop set p_hash = round(rand() * 999); set str='book'; insert into test.users (name,password) VALUES (concat(str,'_',i+1),PASSWORD(p_hash)); set i = i+1; if (i = it) then leave myloop; end if; end loop myloop; endObject info: Table: users Columns: id int(10) UN PK AI name varchar(45) password char(41)Time: mysql> call insertData(10000); Query OK, 1 row affected (9 min 38.22 sec)2. Firebird Stored Procedure SET TERM ^ ; CREATE PROCEDURE INSERDATA ( IT integer ) --iteration number AS DECLARE VARIABLE i integer; BEGIN i = 0; while ( i < it ) do begin INSERT INTO PRODUCT( CODE,NAME,PASS) VALUES(:i, 'jazz_' || :i, fb_hash(round(rand() * 999))); i = i + 1; end END^ SET TERM ; ^ COMMIT;Object Info: Table: product columns CODE integer, NAME varchar(45), PASS CHAR(41)Time: ( for 10 000 records it takes less than 1 sec for execution) Executing statement... Statement executed (elapsed time: 0.063s). 31464 fetches, 11084 marks, 0 reads, 0 writes. 10000 inserts, 0 updates, 0 deletes, 5 index, 0 seq. Delta memory: 24264 bytes. PRODUCT: 10000 inserts. 0 rows affected directly. Total execution time: 0.151s Script execution finished.Do you see something wrong in mysql stored procedure code? jazz. Edited by jazzman1, 31 July 2014 - 03:21 PM. Hi I'm trying to figure out how to calculate how long since a datevariable I have stored is from whenever the page is loaded.. I currently have a stored datevariable in the format: YYYY-MM-DD H:m:s ... So basically what I wish to accomplish is figuring out whenever i load the page which has stored this variable, how much time has passed. I want it to show up as for example : '10 minutes ago'.. '1 hour 25minutes ago' if it's the same day.. if its more than 1 day old it's enough to show only the number of days.....'1week 3 days ago' etc etc I try to get how long my message was sent with this... $Now = strtotime ("now"); $dateEnvoi = $fetchDiscussion['dateEnvoi']; //my date from my DB $timeEnvoi = mktime($dateEnvoi); $TempsEnvoi = $dateNow - $dateEnvoi; and it try to get how long it was post ... same thing as on facebook... like the 26 minutes ago from FB how can i do it ? Hello , I've this code its skip the weekend ,and I've a table for special events has field datetime. What I need when its come across this datetime skip it like it does with the weekend. there's the code Code: [Select] <?php$database_date = '2011-08-12, 07:00:00'; //this comes from your database, $updated_time = strtotime('+' . hoursLeft($database_date,7,16,24) . ' hours',strtotime($database_date)); //Handle the date:$new_date = date('m-d-Y, H:i:s',$updated_time); //this is when the email should be sent.echo date('m-d-Y, H:i:s',strtotime($database_date)) . '<br />' . $new_date . '<-- you should be emailing at this time!'; //just echo's it to the screen.function hoursLeft($time,$work_starts,$work_ends,$time_to_email,$skip_weekends = true) { //this function handles the count of how many hours you need to fulfill your task. $parts = explode(' ',$time); //split the time off of the date. list($hour, $minute, $second) = explode(':',$parts[1]); //get the hours, minutes, seconds. if($minute == 0) { //if the minutes is over 0, then return a full hour for it $hours = $work_ends - $hour; } else { //otherwise, take into account that this isn't a full hour. $hours = ($work_ends - 1) - $hour; } $day_count = 0; //original day count is 0; for($i = $work_ends,$count = $hours; $count <= $time_to_email; $i++) { //Start the increment at 16, the count at the current hours, keep the count below 25, increment on each loop. if($i > 24) { //if the increment is over 24, reset it to 0. $i = 0; ++$day_count; //increment day_count when i goes over 24 hour limit. if($skip_weekends == true) { //if you want to skip weekends $day = date('l',strtotime("+ {$day_count} days",strtotime($time))); //get the full text of the current day the hours are pointing to. if(in_array($day, array('Saturday','Sunday'))) { //and current day is in the weekend. $hours += 24; //add 24 hours to the count. continue; //restart loop, before any counting takes place. } } } if($i > $work_starts && $i <= $work_ends) { //if the increment is between 7 and 16, add to the count, which will break the loop at 24. $count += 1; } $hours += 1; //add to the hours, the loop breaks at a count of 24, which will give us the total hours to add to the updated_time above. } return $hours; //return hours}?> OUTPUT: Code: [Select] 08-12-2011, 07:00:0008-16-2011, 14:00:00<-- you should be emailing at this time!9 hours for Friday:9 hours for Monday:7 hours for Tuesday:= 24 hours. I'm waiting for your replys.. I keep getting this error, because people can track their support tickets by using a MD5 encrypted code upon submitting, and I'm wondering if maybe it's too long? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by FROM replies WHERE replyto = 'c8c3455c5efadc80b05316c412ab61e6' ORDER BY id D' at line 1 Query: Code: [Select] $replies = mysql_query("SELECT message,by FROM replies WHERE replyto = '$id' ORDER BY id DESC") or die(mysql_error()); I've written a script thats going to take a really long time to execute... Whats the best way to do this as far as the server not timing out? My script is calculating some statistics based on other tables in the database and then storing them in another table. The results are going to be hundreds of thousands or maybe even millions of rows. is it possible to get an ajax call to execute a php script that will continue running even if the user leaves my site? i have used cron jobs and tokens to do in past but this can result in 1 min delay. If I break up this long line of code will it still work correctly? Original... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Desired... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Or maybe... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Debbie |