Jump to content


Photo

Crontab Execution


  • Please log in to reply
1 reply to this topic

#1 schandhok

schandhok
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 October 2006 - 09:40 PM

Hi Guys
Here is my php file that i execute through crontab setting

<?php
include "register_globals.php";

$sql_user='chandhs'; // user mysql
$sql_password='gnome007'; // 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....last/Blast.cgi");
# curl_setopt($blas,CURLOPT_POSTFIELDS,trim($my_guery_h));

curl_setopt($blas,CURLOPT_URL,"http://www.ncbi.nlm....last/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.n
ih.gov/blast/Blast.cgi\"",$mail_respons_text);
#    echo $mail_respons_addr."<br>".$mail_respons_text."<br>",$my_query,"<br>";
#  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. ???

#2 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,892 posts
  • LocationCanada

Posted 25 October 2006 - 10:21 PM

Your Mail function site within a WHILE loop. So every time the the loop is traversed an email will be gererated.

The WHILE loop is based upon the records queried from the database. So, you will get one email for every record that is returned from the query.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users