Jump to content
MakeWebGames

Cron problems


thebobby

Recommended Posts

<?
       // Commandline only    
       if(!isset($_SERVER['argc']))
       die("Reticulating Splines");

require_once("dbcon.php");
require_once("classes.php");

//REGULAR CRON SCRIPT
$num_updates = 1;

$num_updates = 1;
$result = mysql_query("SELECT * FROM `grpgusers`");
while($line = mysql_fetch_assoc($result)) 
{
	$updates_user = new User($line['id']);

	if($updates_user->rmdays > 0) 
	{$multiplier = .25;
	} 
	else 
	{$multiplier = .20;
	}

	$username = $updates_user->username;

	$newawake = $updates_user->awake + ($num_updates * 20);
	$newawake = ($newawake > $updates_user->maxawake) ? $updates_user->maxawake : $newawake;

	$newhp = $updates_user->hp + round($num_updates * $updates_user->maxhp * $multiplier);
	$newhp = ($newhp > $updates_user->maxhp) ? $updates_user->maxhp : $newhp;

	$newenergy = $updates_user->energy + round($num_updates * $updates_user->maxenergy * $multiplier);
	$newenergy = ($newenergy > $updates_user->maxenergy) ? $updates_user->maxenergy : $newenergy;

	$newnerve = $updates_user->nerve + round($num_updates * $updates_user->maxnerve * $multiplier);
	$newnerve = ($newnerve > $updates_user->maxnerve) ? $updates_user->maxnerve : $newnerve;


	mysql_query("UPDATE `grpgusers` SET `awake` = '".$newawake."', `energy` = '".$newenergy."', `nerve` = '".$newnerve."', `hp` = '".$newhp."', `gcrime` = '0' WHERE `id`=\"$updates_user->id\"");
}	




?>
Edited by illusions
added tags
Link to comment
Share on other sites

<?php
// Commandline only   
if(isset($_SERVER["REMOTE_ADDR"]) && ($_SERVER["REMOTE_ADDR"] != $_SERVER["SERVER_ADDR"]))
die('Access Is Denied!');

require_once("dbcon.php");
require_once("classes.php");

//REGULAR CRON SCRIPT
$num_updates = 1;
$result = mysql_query("SELECT `id` FROM `grpgusers`");
while($line = mysql_fetch_assoc($result))	{
$updates_user = new User($line['id']);
$multiplier = ($updates_user->rmdays) ? .25 : .20;

$username = $updates_user->username;
$newawake = $updates_user->awake + ($num_updates * 20);
$newawake = ($newawake > $updates_user->maxawake) ? $updates_user->maxawake : $newawake;
$newhp = $updates_user->hp + round($num_updates * $updates_user->maxhp * $multiplier);
$newhp = ($newhp > $updates_user->maxhp) ? $updates_user->maxhp : $newhp;
$newenergy = $updates_user->energy + round($num_updates * $updates_user->maxenergy * $multiplier);
$newenergy = ($newenergy > $updates_user->maxenergy) ? $updates_user->maxenergy : $newenergy;
$newnerve = $updates_user->nerve + round($num_updates * $updates_user->maxnerve * $multiplier);
$newnerve = ($newnerve > $updates_user->maxnerve) ? $updates_user->maxnerve : $newnerve;

mysql_query('UPDATE `grpgusers` SET `awake` = "'.$newawake.'", `energy` = "'.$newenergy.'", `nerve` = "'.$newnerve.'", `hp` = "'.$newhp.'", `gcrime` = "0" WHERE `id` = '.$updates_user->id);

++$num_updates;	
}
file_put_contents('5mincron_check.txt', "{$num_updates} updates on ".date('l jS \of F Y h:i:s A')."\n");
?>

 

A bit more efficient, there is no need to select *(everything) in the grpg users as we only use the ID. Also, this outputs into a "5mincron_check.txt" file, each update that happens. So you can follow that to see if something is stopping or not.

Edited by HauntedDawg
Link to comment
Share on other sites

Just as a reference for other people with this problem...

The cronjobs on cPanel, or anywhere else really, executes a command: a shell command.

The difference in methods of executing the files via various ways.

cURL / wget

When using something similar like below, an HTTP(web) request is sent to the scripts/web page:

curl http://your.domain.tld/scripts/your_cron.php # normally, an email sent if using cPanel when this is executed
wget http://your.domain.tld/scripts/your_cron.php # note, this will save the output into a file

 

This in essence is just the same as you opening up the URL in your browser.

It's not recommended to use this approach, as anyone with the URL will be able to execute the script as well unless you protect it(not worth the hasstle).

PHP

This approach is really the only way you should be using, it gives security in the sense that the script will not be executable through the webserver.

You would put the PHP file/script below(lower level in terms of directory) your web (root)directory, and issue a command that will call the PHP interpreter wit han absolute path to the file.

php -f /home/you/scripts/your_cron.php

 

No additional security is used for this approach, since no HTTP request is being made to execute the file.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...