mira
mira

Reputation: 1

How can I convert this code in curl or similar example?

I got this function from Stack Overflow and it helped me really a lot as it worked fine on my local system but its not working on my server (Bluehost). What might be the issue, or how can I test it on my server to get it working?

  function post_async1($url, array $params)
  {
    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);

    echo $out = "GET ".$parts['path']."?$post_string"." HTTP/1.1\r\n";//you can use POST instead of GET if you like
    $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";
    fwrite($fp, $out);
    fclose($fp);
  }

$params['id'] = 36; post_async1('http://uda:8888/sendmail.php', $params);

Upvotes: 0

Views: 32

Answers (1)

Saurabh Sharma
Saurabh Sharma

Reputation: 440

The fsockopen function will work for outbound connection to any URL on port 80 (HTTP) or 443 (HTTPS). If fsockopen is attempting to use another port, it will not work until we have added that port to the firewall. you need to request them to open the socket bluehost help

Upvotes: 1

Related Questions