I have really strange problem with curl working on Laravel 5.5 and php7. When i use just single connection i don't have any problem with this curl function:
function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
I'm trying to access local php file with information, multiple times at the same time. I'm using VHOST with the apache: server.local and the file is in that folder server.local/request.php. So with this curl function above it's working as i'm expecting.
The problem is when i have to use it in another function to get multiple requests at the same time with curl_multi and here is the code:
foreach($data as $key => $fetch) {
$info[$key]['name'] = $fetch->name;
$info[$key]['url'] = 'http://server.local/request.php?url='.$fetch->url;
}
$multi = curl_multi_init();
$channels = array();
foreach ($info as $url) {
$ch = curl_init();
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_URL, $url['url']);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_HTTPGET, 1);
//curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
//curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
//curl_setopt($ch, CURLOPT_PORT, 80);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_REFERER, $url['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
curl_multi_add_handle($multi, $ch);
$channels[$url['url']] = $ch;
}
$active = null;
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($multi) == -1) {
continue;
}
do {
$mrc = curl_multi_exec($multi, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
$i = 0;
dd($channels);
foreach ($channels as $channel) {
$info[$i]['data'] = curl_multi_getcontent($channel);
curl_multi_remove_handle($multi, $channel);
$i++;
}
curl_multi_close($multi);
So i tried every combination in the curl_setopt with the commented and uncommented lines. Nothing worked! The only way it works is when i put the request.php in the main web directory and changed server.local with 127.0.0.1. I tried even to apply working real website, and still didn't get anything.
The code i receive in dd($channels); is this:
array:1 [▼
"http://server.local/request.php" => curl resource @276 ▼
url: "http://server.local/request.php"
content_type: null
http_code: 0
header_size: 0
request_size: 0
filetime: -1
ssl_verify_result: 0
redirect_count: 0
total_time: 0.0
namelookup_time: 0.0
connect_time: 0.0
pretransfer_time: 0.0
size_upload: 0.0
size_download: 0.0
speed_download: 0.0
speed_upload: 0.0
download_content_length: -1.0
upload_content_length: -1.0
starttransfer_time: 0.0
redirect_time: 0.0
redirect_url: ""
primary_ip: ""
certinfo: []
primary_port: 0
local_ip: ""
local_port: 0
}
]
And just for the protocol, in request.php i have only one Hello World... The request is returning "Hello World" in the browser load, and even in Terminal curl request. I don't know what i've could done wrong? Please help :/