cron - PHP: Line running twice when a POST is called first -


i have few lines of code in script, , if part executes, part b executes twice (that is: cron.php file added crontab twice). odd, because if comment out part a, part b executes once.

why happening? missing?

// part $url = "https://api.sendgrid.com/apiv2/customer.add.json"; $input = "api_user=$sendgrid_user_account&api_key=$sendgrid_master_password&username=$custname.domain.com&website=$sendgridsubuserdomain&password=$sendgridsubusersmtppass&con    firm_password=$sendgridsubusersmtppass&first_name=$first&last_name=$last&address=$sendgridsubuseraddress&city=$sendgridsubusercity&state=$sendgridsubuserstate&zip=$    sendgridsubuserzip&email=$email&country=$sendgridsubusercountry&company=$custname&phone=$sendgridsubuserphone"; $sendgrid_output = postcurl($url, $input, false, false);  // part b chdir("/etc/nginx/"); exec("2>&1 ./addcron.sh $custname"); 

supporting functions:

function posturl($url, $data, $headers = null, $json_format = true) { // json format used if $data formatted string     $curl_result = postcurl($url, $data);     if($curl_result != false) return $curl_result;      $data_query = http_build_query($data);     $opts = array('http' => array('method' => 'post', 'content' => $data_query));      if($headers) {         $opts['http']['header'] = $headers;     }     else {         $opts['http']['header'] = "content-type: application/x-www-form-urlencoded"; }     $st = stream_context_create($opts);     $fp = fopen($url, 'rb', false, $st);      if(!$fp) {         //$result = http_post_fields($url, $data); todo: add in once aws's php updated include http_post_fields function          //if(!empty($result)) return $result;     }     $result = stream_get_contents($fp);     if(empty($result)) {         //$result = http_post_fields($url, $data);         //if(!empty($result)) return $result;     }      return false; // if else fails, false }  function postcurl($url, $values, $boolean_return = false, $json_format = true) {     $ch = curl_init();      curl_setopt($ch, curlopt_url, $url);     curl_setopt($ch, curlopt_post, 1);     if(is_array($values)) {         $values_string = "";         foreach($values $key => $value) $values_string .= "$key=$value&";         $values_string = substr($values_string, 0, -1); // remove last "&"     }     else { // if it's not array, assume json         $values_string = $values;         if($json_format == true) {                 $input_array = array(                 'content-type: application/json',                 'content-length: ' . strlen($values_string));         }         else {             $input_array = array('content-length: ' . strlen($values_string));         }          curl_setopt($ch, curlopt_httpheader, $input_array);     }      curl_setopt($ch, curlopt_postfields, $values_string);      // in real life should use like:     // curl_setopt($ch, curlopt_postfields,     //          http_build_query(array('postvar1' => 'value1')));      // receive server response ...     if($boolean_return == false) curl_setopt($ch, curlopt_returntransfer, true);      $server_output = curl_exec ($ch);     curl_close ($ch);      return $server_output; } 

the addcron.sh script:

#!/bin/bash custname="$1" (crontab -l; echo "* * * * * /usr/bin/php -f /var/www/html/$custname/cron/cron.php" ) | crontab - 


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -