• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Why does my php / mysql code work differently when cron'd ?

Please see my script below.

If I run the script in my browser it works fine. if cron't it doesn't

It seems like the delete query isn't working.
The page which relies on the data shows twice as much data as it should, a duplicate of every record.

Any ideas?
<?php
 
list($usec, $sec) = explode(' ',microtime());
$querytime_before = ((float)$usec + (float)$sec);
 
include "../php/_con.php";
include "../php/_stdfuncs.php";
 
populate_front_temp_table();
 
list($usec, $sec) = explode(' ',microtime());
$querytime_after = ((float)$usec + (float)$sec);
$querytime = $querytime_after - $querytime_before;
$strQueryTime = '%01.4f';
echo sprintf($strQueryTime, $querytime);
 
function populate_front_temp_table() {
 
	global $server;
	global $db;
	global $user;
	global $pass;
	global $sBlankMySQLDate;
 
	$con = mysql_connect($server,$user,$pass);
 
	if (!$con) {
		die('Could not connect: ' . mysql_error());
		}
	else {
		mysql_select_db($db, $con);
 
 
		$sql = "DELETE FROM TEMP_FRONT;";
		mysql_query($sql) or die('Error, delete query failed');
 
		$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 1, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 11 AND `Pads`.`ProgramName` LIKE '%DVD%' AND `Pads`.`License` = 'Freeware' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
		mysql_query($sql) or die('Error, insert query failed 11');	
 
		$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 2, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 120 AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
		mysql_query($sql) or die('Error, insert query failed 120');	
 
		$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 3, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 120 AND `Pads`.`License` = 'Freeware' AND  RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
		mysql_query($sql) or die('Error, insert query failed 120 free');
 
		$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 4, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 15 AND `Pads`.`ProgramName` LIKE '%Help Desk%' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
		mysql_query($sql) or die('Error, insert query failed 15');
	
		$sql = "INSERT INTO TEMP_FRONT(section, PadID, CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL) SELECT 5, Pads.PadID, Pads.CatID, IconSoureURL, OsStr, PadURL, PageName, ProgramName, ProgramVersion, ReleaseStatus, English45, License, DownloadURL FROM `Pads` INNER JOIN `Downloads_Count` ON `Downloads_Count`.`CatID` = `Pads`.`CatID` AND `Downloads_count`.`PadID` = `Pads`.`PadID` WHERE `Downloads_Count`.`CatID` = 9 AND `Pads`.`ProgramName` LIKE '%DVD Ripper%' AND RemoveMeDate='" . $sBlankMySQLDate . "' ORDER BY `Downloads_Count`.`tot_downs` DESC LIMIT 0 , 5;";
		mysql_query($sql) or die('Error, insert query failed 9');
	
 
	}
 
	mysql_close($con);
 
}
 
?>

Open in new window

0
mindwarpltd
Asked:
mindwarpltd
  • 2
  • 2
1 Solution
 
hyarionCommented:
If it is your own server the easiest way to test it is to run the cron command directly from the console, this way you can see if there are any errors being encountered.

The include command can also cause issues sometimes, usually a full directory path is needed and not a relative one.

e.g.
Instead of include "../php/_con.php";
Use: "/srv/www/htdocs/mywebsite/php/_con.php";
(note that the above /srv/www/htdocs/ is an example and may not apply to your server)
0
 
Tomas Helgi JohannssonCommented:
    Hi!

Is your cronjob setup correctly ?
http://www.modwest.com/help/kb5-125.html
Other does the db-user have delete privileges on the table ?
Check the hosts that the user is allowed to connect from and see
if the delete privileges are on all hosts.

Regards,
   Tomas Helgi
0
 
Tomas Helgi JohannssonCommented:
Yes, hyarion is right.
That is probably the case. As the cron server doesn't activate the $_SERVER[DOCUMENT_ROOT] variable as
mentioned in the link I provided.

Regards,
    Tomas Helgi
0
 
mindwarpltdAuthor Commented:
OK, I've added the full path.

Its a windows server, so I don't think the file permissions will be a problem.

Do you think theres anything else I can try?
0
 
mindwarpltdAuthor Commented:
I think thats worked
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now