Jump to content

[SOLVED] [Solved]PHP Script Kind of Locking Up.


ChrisMayhew

Recommended Posts

<?php
include('Settings.php');

//Variables
$CurrentTime = time();

//$Active = mysql_query("SELECT UserID, Username, Time, Active FROM activeusers ");

while ($GetActive = mysql_fetch_array(mysql_query("SELECT UserID, Username, Time, Active FROM activeusers "))) {
		$UserID = $GetActive['UserID'];
		$Username = $GetActive['Username'];
		$Time = $GetActive['Time'];
		$Active = $GetActive['Active'];

If ($Active == '1') {
			If ($CurrentTime >= $Time) {
 				 mysql_query("UPDATE activeusers SET Active = '0' WHERE Username = '$Username' ");
			}
}

}

?>

 

Hey

 

I am trying to make a Cron job script, What i would like this to do is go through a table on a database and if the CurrentTime is greater than the Time in the database then set Active to 0.

 

Now when i run this script through a browser it takes forever with the loading, and then gives me this error:

Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\Project\includes\ActiveUsersCron.php on line 9

 

My understanding is that it is getting stuck somewhere on the code, the strange thing is it will process the first row in the table but after this it just stops.

 

Any help would be greatly appreciated

Link to comment
Share on other sites

Execute the query first

<?php 
$query = "SELECT UserID, Username, Time, Active FROM activeusers ";
$stm = mysql_query($query);
while ($GetActive = mysql_fetch_array($stm) ) {
snip...
?>

 

That did the trick :)

 

That has been bugging me for about the last hour and a half.

 

Thank you :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.