Page 1 of 1

Cron Job

Posted: Wed Nov 04, 2009 1:07 am
by khurram_micro
Hi friends I am a student and working on a project for my university
I am having some problem to run PHP script as cron job on my server.i tried alot but can not find any possible solution for this :banghead: ... On my server PHP is Installed as APache Module (Not as CGI)

I Tried all of the following
0 2 * * * php /var/www/domainname/catalog/admin/abc.php
and this as well
0 2 * * * /usr/bin/php /var/www/domainname/catalog/admin/abc.php

I also tried this.. I set the file permission to 777 and then i write this
0 2 * * * /var/www/domainname/catalog/admin/abc.php

But nothing happens, Point to note is when i run this command in SSH of my server it successfully run the script without any error
php /var/www/domainname/catalog/admin/abc.php

Can any one help me immediatly it is urgent ...

Re: Cron Job

Posted: Wed Nov 04, 2009 6:32 am
by VladSun
How do you edit your conjob list? By using

Code: Select all

crontab -e
?

What's the user you try to run this cronjob by?
Try

Code: Select all

*/1  * * * * /usr/bin/php /var/www/domainname/catalog/admin/abc.php 2>&1 > /path/file_name_here
And make sure /path/file_name_here is world writable (chmod 666).
Wait for 1 minute and see the contents of this file.

Re: Cron Job

Posted: Thu Nov 05, 2009 10:44 pm
by khurram_micro
VladSun wrote:How do you edit your conjob list? By using

Code: Select all

crontab -e
?

What's the user you try to run this cronjob by?
Try

Code: Select all

*/1  * * * * /usr/bin/php /var/www/domainname/catalog/admin/abc.php 2>&1 > /path/file_name_here
And make sure /path/file_name_here is world writable (chmod 666).
Wait for 1 minute and see the contents of this file.
user is root for which i m running every cron and every ssh command.
I tried this what you mention but it did not solve my problem.
My Server API is APACHE Module .. I think their is some difference in cron statments for CGI and APACHI ... Can any one plz help

Re: Cron Job

Posted: Fri Nov 06, 2009 1:35 am
by VladSun
khurram_micro wrote:I tried this what you mention but it did not solve my problem.
My Server API is APACHE Module .. I think their is some difference in cron statments for CGI and APACHI ... Can any one plz help
It wasn't meant to solve your problem, but to show you the error messages from your script.
Is there anything in "/path/file_name_here" file?
Do you mind posting the /var/www/domainname/catalog/admin/abc.php code?

PHP CLI and PHP Apache module have spearate php.ini files - maybe this the problem (e.g. some extensions are not loaded)?

Re: Cron Job

Posted: Fri Nov 06, 2009 11:05 pm
by khurram_micro
No i never mind ,.....yes you are right PHP CGI and PHP apache have different scenrio and this is the problem.... i tested my script on PHP CGI as well and their it run very Well without any problem
here is my script

Please Dont concentrate on queries and query variables because i changed them in hurry so might have some problem but try to check the code.. according to me the code does not have any error as it is running well on my CGI Server but PHP server is the main problem...

////////////////// Code is ///////////////
<?php
$con = mysql_connect('localhost','user','pass');
mysql_select_db('database',$con);
$cnt=1;
$f=0;
$flag = 0 ;
$nor_item = " ";
$ch=mysql_query("select * from mytable order by id desc");
while($row=mysql_fetch_array($ch))
{
$cat_query=$row['id'];
$category=mysql_query("select * from mytable 2",$con);
if ($category)
{
$row_cat=mysql_fetch_assoc($category);
//echo '<td><font face="Verdana" size="2">'. $row_cat['pcategory_id'].'</td>';
$cat_id=$row_cat['category_id'];
$supplier=mysql_query("select * from mytable 3",$con);}
else
{
}
if ($supplier)
{
$supp_row=mysql_fetch_assoc($supplier);
}
else {
}
if ($category && $supplier)
{
$temp_table = "INSERT INTO `mp` (`id`,`cid`, `cname`, `pname`, `quantity`, `supplier`, `supplier_email`) VALUES ('$cat_query','$cat_id','".$supp_row['pc']."','".$row['pr']."','".$row['qu']."','". $supp_row['su']."','".$supp_row['s']."')";
mysql_query($temp_table,$con);
}
else
{

$not_registered_items.=$row['products_name']. "\r\n";

}
//echo "</tr>";
$cnt++;
}
$distinct = "SELECT DISTINCT (`cname`) FROM `mp`";
$res_distinct = mysql_query($distinct,$con);
$categories = array();
while ($row_distinct = mysql_fetch_assoc($res_distinct))
{
$categories[] = $row_distinct['cname'];
}
foreach($categories as $show)
{
//echo "<br>For ".$show." We have the following <br>";
$pro_distinct = "select * from mp where category_name = '$show'";
$pro_distinct_result = mysql_query($pro_distinct,$con);
//echo "<ul>";
$random_hash = md5(date('r', time()));
$headers = "From: abc <abc@abc.co.uk> \r\nReply-To: sales@abc.co.uk";
//add boundary string and mime type specification
$headers.= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$subject = "Products Price and Availibilty";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<b>Dear Sir / Madam</b>
<table width="480" border="1">
<tr>
<td><div align="center"><b>MID</b></div></td>
<td><div align="center"><b>Name</b></div></td>
<td><div align="center"><b>Required </b></div></td>
<td><div align="center"><b> </b></div></td></tr>
<?php
while ($pro_row_distinct = mysql_fetch_assoc($pro_distinct_result))
{
$to = $pro_row_distinct['email'];
?><tr>
<td>&nbsp;&nbsp;<?php echo $pro_row_distinct['id']; ?>&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;<?php echo $pro_row_distinct['pe']; ?>&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;<?php echo $pro_row_distinct['ty'];?>&nbsp;&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
<?php
}?>
</table>
<br />
<?php
$msg= ob_get_clean();
$bits = explode(",", $to);
foreach($bits as $to)
{
$mail_sent=mail($to,$subject,$msg,$headers);
} }
$truncate_query = "truncate `mp`";
mysql_query($truncate_query,$con);
if ($not_registered_items != " ")
{
$to="abcabc@hotmail.com";
$header="From: abc <abc@abc.co.uk>";
$subject="noducts";
$mail_sent=mail($to,$subject,$not_registered_items,$headers);
}
die (" "); ?>