I'm wondering:
$i = 0;
while ($row = $result->fetch_object()) {
$data = curl_multi_getcontent($ch[$i]);
$json_data = json_decode($data);
var_dump($json_data);
Are you forgetting to increment $i? If so, you already grabbed the content for $ch[0], and then you call curl_multi_getcontent again.
Also, I've written a blog post covering concurrent requests with PHP's cURL extension, and it contains a general function for curl multi requests. You could call this function in the following manner:
$responses = multi([
$requests = [
['url' => 'https://example.com/search/username1/'],
['url' => 'https://example.com/search/username2/'],
['url' => 'https://example.com/search/username3/']
]
$opts = [
CURLOPT_CAINFO => 'cacert.pem',
CURLOPT_USERPWD => "username:password"
]
]);
Then, you cycle through the responses array:
foreach ($responses as $response) {
if ($response['error']) {
// handle error
continue;
}
// check for empty response
if ($response['data'] === null) {
// examine $response['info']
continue;
}
// handle data
$data = json_decode($response['data']);
// do something
}
Using this function, you could make a simple test of accessing https sites using the following call:
multi(
$requests = [
'google' => ['url' => 'https://www.google.com'],
'linkedin' => ['url'=> 'https://www.linkedin.com/']
],
$opts = [
CURLOPT_CAINFO => '/path/to/your/cacert.pem',
CURLOPT_SSL_VERIFYPEER => true
]
);