Php curl request problem, script request has no return, browser is feasible.

/ / curl request operation

public function curlFast($urls = array(), $callback = "",$time = 2000,$head = null)
{
    $t = microtime(true);
    $response = array();
    if (empty($urls)) {
        return $response;
    }
    $chs = curl_multi_init();
    $map = array();
    $i = 0;
    foreach($urls as $url){
        $i_arr[$url] = $i;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT_MS , $time);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        if($head !== null){
            curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
        }
        curl_setopt($ch, CURLOPT_NOSIGNAL, true);
        curl_multi_add_handle($chs, $ch);
        $map[strval($ch)] = $url;
        $iPP;
    }
    
    do{
        if(microtime(true) - $t > $time){
            break;
        }
        if (($status = curl_multi_exec($chs, $active)) != CURLM_CALL_MULTI_PERFORM) {
            if ($status != CURLM_OK) { break; } //curl_multi_exec
            while ($done = curl_multi_info_read($chs)) {
                if(microtime(true) - $t > $time){
                    break;
                }
                $info = curl_getinfo($done["handle"]);
                $error = curl_error($done["handle"]);
                $result = curl_multi_getcontent($done["handle"]);
                $url = $map[strval($done["handle"])];
                $this -> vardump($url);
                $rtn = compact("info", "error", "result", "url");
                if (trim($callback)) {
                    $callback($rtn);
                }
                //    
                $result = $this -> strEncoding($info["content_type"],$result);            //    
                
                
                $response[$i_arr[$url]] = $result;
                curl_multi_remove_handle($chs, $done["handle"]);
                
                curl_close($done["handle"]);
                //    select
                if ($active > 0) {
                    curl_multi_select($chs, 0.5); //0.5
                }
                $iPP;
            }
        }
    }
    while($active > 0); //
    curl_multi_close($chs);
    return $response;
}

/ / create header information

public function createHead($type){
    $head = array();
    switch($type){
        case "gizp":
            
            break;
        default:
            $head = array(
                "Content-Type:text/xml",
                "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                "Accept-Language: zh-CN,zh;q=0.9",
                "Cache-Control: max-age=0",
                "Connection: keep-alive",
                "Upgrade-Insecure-Requests: 1",
                "User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
            );
    }
    return $head;
}

this is the code, api is not convenient to post because it belongs to the company. The problem is that the request is required to be GBK encoded. Does this matter? When the curl request is scripted, no data is returned (the request data should be incorrect because there are no errors. ). But I took the request url and the data will be returned when the browser enters directly, and the data is correct.

Php
Mar.20,2021

I also encountered this problem, and I found that it has something to do with the server-side environment. The same code does not work locally, but the return value can be typed out by putting it on the server

.
Menu