PHP fsockopen to curl conversion

女生的网名这么多〃 提交于 2019-11-29 16:33:44

This is the equivalent using cURL,

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "http://" . $host . $request); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
    curl_setopt($ch, CURLOPT_TIMEOUT, 2); 
    $response = curl_exec($ch); 
    curl_close($ch);      

BTW, it's not safe to make query string like that. You should use http_build_query() to build it so it's properly encoded.

I suggest you to use this script. This is totally awesome: http://www.bin-co.com/php/scripts/load/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!