Help fixing php/api/curl code please

后端 未结 1 525
醉酒成梦
醉酒成梦 2021-01-27 10:05

What I have in place, is a domain availability check, which connects up to an API and outputs \"Available: and Unavailable:\" from $tmp. Ths below code will only check the avail

1条回答
  •  借酒劲吻你
    2021-01-27 10:35

    This should answer your question: Persistent/keepalive HTTP with the PHP Curl library?

    comment followup:

    function getCurlPage($pageSpec) {
        if (is_null($ch)) 
            static $ch = curl_init($pageSpec);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        } else {
            curl_setopt($ch, CURLOPT_URL, $pageSpec);
        }
        $tmp = curl_exec($ch);
        ... do NOT close the curl handle, otherwise do the rest the same as before ...
    }
    

    Probably won't work as is, doing this off the top of my head and with only 2 hours sleep, but this should be enough to get you started.

    And by the way, there's no need to do doublequotes for GetCurlPage("$url"), it's a waste of parser time, as PHP will have to create a new empty string, stuff $url into it, and pass the new string on down. Just do GetCurlPage($url).

    0 讨论(0)
提交回复
热议问题