SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old August 6th, 2002, 08:46 AM
manduwok manduwok is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 2 manduwok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Simple question from a newbie

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

Reply With Quote
  #2  
Old August 6th, 2002, 03:22 PM
Coyote Coyote is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 8 Coyote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I wonder what the server load would be like if this routine looped every 2 seconds?

Reply With Quote
  #3  
Old August 6th, 2002, 04:04 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
that code would execute 200 000 times, not every two seconds.. what are you going to use this for?
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #4  
Old August 6th, 2002, 06:57 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
thats a hell of a load on a server, i hope your running linux

*laughs @ MS*

Reply With Quote
  #5  
Old August 6th, 2002, 07:01 PM
manduwok manduwok is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 2 manduwok User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes I'm running linux. The little php function is for work.

Reply With Quote
  #6  
Old August 7th, 2002, 02:26 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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...

Reply With Quote
  #7  
Old August 7th, 2002, 09:21 AM
Phynias Phynias is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 18 Phynias User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Simple question from a newbie


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway