Jump to content

Archived

This topic is now archived and is closed to further replies.

schandhok

Crontab Execution

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.