phpcodeigniterfsockopen

fsockopen returns 'bool(false)'


My question title seems to be same with other questions but issue is different from others. My code:

        $post_string = http_build_query($params);
        $parts = parse_url($url);       
        $errno = 0;
        $errstr = "";

        $fp = fsockopen($parts['scheme'].'://' . $parts['host'], isset($parts['port']) 
                   ? $parts['port'] : 443, $errno, $errstr, 30);            
        echo "<pre>"; var_dump($fp);

My parts array is:

Array
(
    [scheme] => http
    [host] => local.abhibus.com
    [path] => /search/distanceC
)

can anyone please let me know what is the issue in the above code which cause to return false. Thanks in advance.


Solution

  • Issue with fsockopen function. to test in local and un-secure servers, we have to remove $parts['scheme'].'://' from fsockopen function call.

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