...

View Full Version : Crontab Execution Problem



schandhok
10-25-2006, 11:53 PM
Hi Guys
Here is my php file that i execute through crontab setting



<?php
include "register_globals.php";

$sql_user='******'; // user mysql
$sql_password='******'; // password mysql 4 user

$blas=curl_init();

$db=mysql_connect('localhost',$sql_user,$sql_password);
mysql_select_db("blast",$db);
$rez=mysql_query("SELECT s_time,s_query_last,s_cdate,u_mail FROM search, users WHERE s_user=u
_id");
while(list($response_time,$my_query,$cdate,$mail_respons_addr)=mysql_fetch_row($rez)){
# $file_mail_respons = fopen('/tmp/.mailrespons.txt', 'w');
$file_mail_respons = fopen('mailrespons.txt', 'w');
$flag=false;
if($my_query!=''){
switch($response_time){
case '0': break;
case '1':$flag=true; break;
case '2':
if(date('w')==='1'){
$flag=true;
}
break;
case '3':
if(date('d')==='01'){
$flag=true;
}
break;
}
}
if($flag){
$blas=curl_init();
# curl_setopt($blas,CURLOPT_URL,"http://www.ncbi.nlm.nih.gov/blast/Blast.cgi");
# curl_setopt($blas,CURLOPT_POSTFIELDS,trim($my_guery_h));

curl_setopt($blas,CURLOPT_URL,"http://www.ncbi.nlm.nih.gov/blast/Blast.cgi");
curl_setopt($blas,CURLOPT_POSTFIELDS,$my_query);
curl_setopt($blas,CURLOPT_FILE,$file_mail_respons);
curl_exec($blas);
curl_close($blas);
fclose($file_mail_respons);

$file_mail_respons = fopen('mailrespons.txt', 'r');
# $file_mail_respons = fopen('/tmp/.mailrespons.txt', 'r');
$mail_respons_text = fread($file_mail_respons,100000);
fclose($file_mail_respons);
#$temp=$mail_respons_text;
$temp_response=str_replace("<form action=\"Blast.cgi\"","<form action=\"http://www.ncbi.nlm.nih.gov/blast/Blast.cgi\"",$mail_respons_text);
# echo $mail_respons_addr."
".$mail_respons_text."
",$my_query,"
";
# Mail($mail_respons_addr,"",$mail_respons_text);
Mail($mail_respons_addr,"",$temp_response);
#echo $temp_response;
}
}
mysql_close($db);
exit;
?>



My problem is that in my site when i choose this file to run daily, i get results in my email around 60 in a day same email. Why doesnt it send me just one email instead of sending 60 at a time?
My crontab setting for running this file is :
* 0 * * * /home/chandhs/blast_site/myblast4cron.php

Pls help.

Spookster
10-26-2006, 03:52 AM
I removed your database login info. I wouldn't recommend posting that in the future. Also please use the forum php tags when posting code.

Anyways are you asking why is it sending you 60 emails each with a response verses sending you one email with 60 responses? Probably because you have the mail command inside the while loop. It will generate a new email for each iteration of the loop.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum