Yii Framework Forum: Fsockopen Or Background Post/get Methods ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Fsockopen Or Background Post/get Methods ? Rate Topic: -----

#1 User is offline   Azy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 16-May 12

Posted 27 September 2012 - 11:06 PM

Hi there,

can any body pls explain me why does the below function does not work in Yii ???????? i just executed it in normal php and it works as expected.

i want to run a php page from background with get or post method..

in simple, sending aruguments in url and do some work in background..

for that purpose after having soo much of research, i found a function which simply does that, but still it doesnt work with YII..

the function..

  function backgroundPost($url){
  $parts=parse_url($url);
  
  $fp = fsockopen($parts['host'], 
          isset($parts['port'])?$parts['port']:80, 
          $errno, $errstr, 30);
           
  if (!$fp) {
      return false;
  } else {
      $out = "POST ".$parts['path']." HTTP/1.1\r\n";
      $out.= "Host: ".$parts['host']."\r\n";
      $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
      $out.= "Content-Length: ".strlen($parts['query'])."\r\n";
      $out.= "Connection: Close\r\n\r\n";
      if (isset($parts['query'])) $out.= $parts['query'];
   
      fwrite($fp, $out);
      fclose($fp);
      return true;
  }
}


usage of function.. (after form validates)


$url = Yii::app()->params['hostname'].'/index.php/admin/vendor/notification?salesrep='.$vendors->sales_rep_id;
$this->backgroundPost($url);



in the action..

      $headers = 'From: webmaster@example.com' . "\r\n" .
      'Reply-To: webmaster@example.com' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();
      $salesRep = User::model()->findByPk($_POST['salesrep']);
      mail('$salesRep->email', 'My Subject', 'Message body', $headers);
      exit;


any help is really appreciated. tnx
0

#2 User is offline   Azy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 16-May 12

Posted 27 September 2012 - 11:46 PM

can any body help me to execute this in yii ??

 function curl_request_async($url, $params, $type='POST')
  {
      foreach ($params as $key => &$val) {
        if (is_array($val)) $val = implode(',', $val);
        $post_params[] = $key.'='.urlencode($val);
      }
      $post_string = implode('&', $post_params);

      $parts=parse_url($url);

      $fp = fsockopen($parts['host'],
          isset($parts['port'])?$parts['port']:80,
          $errno, $errstr, 30);

      // Data goes in the path for a GET request
      if('GET' == $type) $parts['path'] .= '?'.$post_string;

      $out = "$type ".$parts['path']." HTTP/1.1\r\n";
      $out.= "Host: ".$parts['host']."\r\n";
      $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
      $out.= "Content-Length: ".strlen($post_string)."\r\n";
      $out.= "Connection: Close\r\n\r\n";
      // Data goes in the request body for a POST request
      if ('POST' == $type && isset($post_string)) $out.= $post_string;

      fwrite($fp, $out);
      fclose($fp);
  }

0

#3 User is offline   Azy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 16-May 12

Posted 28 September 2012 - 12:10 AM

anyone pls ?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users