Fsockopen Or Background Post/get Methods ?

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;

  }

}

[b]usage of function… (after form validates)

[/b]


$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

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);

  }

anyone pls ?