|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Ok guys... I have to write a php function that searches for a file every 2 seconds and times out if the file is not found. I am not told where to search for the file or what the file is. If the file is found, I have to pass it out of the function, preferrably as an object. Here is my skeleton code:
function searchForFile($filename) { if(file_exists($filename)) { return true; else return false; } //end if } //end searchForFile() $twominutes = "200000"; //estimate of how many clock cycles in 2 minutes //search for file for 2 minutes for($i = 0; $i < $twominutes; $i++) { $found = searchForFile ("myfile.txt"); if($found) { echo "I found it !"; break; } //end if } //end for if ($found == false) echo "Timed Out"; //end if |
|
#2
|
|||
|
|||
|
I wonder what the server load would be like if this routine looped every 2 seconds?
|
|
#3
|
|||
|
|||
|
that code would execute 200 000 times, not every two seconds.. what are you going to use this for?
__________________
Best Regards, Håvard Lindset |
|
#4
|
|||
|
|||
|
thats a hell of a load on a server, i hope your running linux
*laughs @ MS* |
|
#5
|
|||
|
|||
|
Yes I'm running linux. The little php function is for work.
|
|
#6
|
|||
|
|||
|
Use something like this:
<?php error_reporting(0); set_time_limit(2); // 2 seconds function searchForFile($filename) { if(file_exists($filename)) return true; else return false; } ?> That will set the maximum length to run a command to 2 seconds. If it fails, error_reporting(0) will make sure an error isn't output.... you can build up from this code... |
|
#7
|
|||
|
|||
|
Your better off making a cronjob, that runs ever 2 minutes.
Also what do u mean you have no idea where the file will be or what its called. How is the script going to get this info then ? EDIT: Just noticed you said 2 seconds. YOu may want to fill us in on what exactly you are trying to do, and for what reasons we may have a simpeler solution for you. Last edited by Phynias : August 7th, 2002 at 09:24 AM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Simple question from a newbie |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|