javascript - php script restarts randomly with same POST data -


i have php script receives parsed data javascript application via xmlhttp.

i'm finding php script stop while it's processing chunk of data , restart same post data sent it. thought maybe javascript's xmlhttp might double firing somehow, i've ruled out inprogress flag shown below.

function sendphp(str, callback){     xmlhttp = new xmlhttprequest();       str = "q=" + encodeuricomponent(str);        xmlhttp.open("post","sendmail.php", true);     xmlhttp.onreadystatechange=function(){         if (xmlhttp.readystate == 4){             inprogress=false;             if(xmlhttp.status == 200){                             callback(xmlhttp.responsetext);             }         }     };     xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded");          if (inprogress==false){           inprogress=true;         xmlhttp.send(str);         }         else{             writedisplayconsole("error: xmlhttp fired twice!");         } } 

if xmlhttp tries send twice error shown , no further packets sent. that's never case php script must restarting on it's own.

bear in mind happens @ random intervals, not @ same time every time same data. causing happen?

the php script writes big text file logs, it?

here's php (but since error happens @ random intervals same data, i'm not sure how problem php code):

<?php  writelog("\n*** sendmail script started ***");  $q = $_post['q'];      //split auth code , verify      $pieces = explode("(<!asplit!>)", $q);      $authc=$pieces[0];      $q=$pieces[1];       if ($authc<>"****"){             echo "!authentification denied.";             writelog ("authentification denied");             die;      }           writelog ("authentification accepted");          //split off packet details      $pieces=explode("(<!psplit!>)", $q);      $tpack=$pieces[0];      $q=$pieces[1];       $pieces=explode("-", $tpack);      $tpacket=$pieces[0];      $ofpacket=$pieces[1];      $totalcontacts=$pieces[2];        //split contact data email message      $pieces = explode("(<!dsplit!>)", $q);      $split=$pieces[0];      $q=$pieces[1];       //assign contacts array      $contacts = explode ("<!", $split);      $tcount=count($contacts);      $tcount=$tcount-1;       echo "(packet ";      echo $tpacket;      echo " of ";      echo $ofpacket;      echo ")- ";       writelog("(packet " . $tpacket . " of " . $ofpacket . ")");           //killswitch check incase double run      checkkillswitch("!startup aborted power set off.",0);      checkkillswitch("!aborted, killswitch set kill",1);      file_put_contents('log/killswitch.txt', "on");       echo $tcount;      echo " contacts processing...";       foreach ($contacts &$value) {       //check killswitch      checkkillswitch("killswitch aborted during runtime",1);                       $split=explode ("^!", $value);              //get contact's details          $firstname= $split[0];          $lastname= $split[1];                  $temail = $split[2];                   if ($firstname<>""){             $mainmessage=str_replace("[firstname]",$firstname,$q);              $mainmessage=str_replace("[lastname]",$lastname,$mainmessage);              //split off subject              $pieces = explode("(/subject)", $mainmessage);              $tsubject=$pieces[0];              $mainmessage=$pieces[1];                      testlogmail($temail, $tsubject, $mainmessage);                  //log progress                       $adder=$adder+1;                      //for log, show progress of total (based on 10 per packet change if different)                     $tadder = (($tpacket-1)*10)+$adder;                      echo ($tadder . ".");                      writelog($tadder . " of " . $totalcontacts . " processed >> " . $temail);                     sleep(rand(2,20));                  }          }  function testlogmail($xaddress, $xsubject, $xmessage){    $tdate=date('d/m/y h:i:s');    $file = 'log/testmaillog.txt';   // open file existing content   $current = file_get_contents($file);      // enter email     $towrite="to: ".$xaddress."\n";     $towrite.="subject: ".$xsubject."\n";     $towrite.="date: ".$tdate."\n";     $towrite.="...\n";   $towrite.=$xmessage."\n";     $towrite.="___________________________________\n\n";      $current .= $towrite;    // write contents file   file_put_contents($file, $current);  }   function writelog($towrite) {   $tdate=date('d/m/y h:i:s');    $file = 'log/testlog.txt';   // open file existing content   $current = file_get_contents($file);   // append new person file   $current .= $towrite." --- ".$tdate."\n";   // write contents file   file_put_contents($file, $current); }   function checkkillswitch($towrite, $killtype){  if ($killtype==0){    $killswitch = file_get_contents('log/killswitch.txt');     if ($killswitch=="on") {     echo $towrite;     writelog($towrite);     die;    }  }   if ($killtype==1){    $killswitch = file_get_contents('log/killswitch.txt');     if ($killswitch=="kill") {     echo $towrite;     writelog($towrite);     die;    }  }   }   writelog("*** sendmail script ended ***"); ?>  


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -