Answer the question
In order to leave comments, you need to log in
Why doesn't cUrl run in a loop?
Hello, I'm asking for help with solving one small problem with the cycle and cUrl. There is the following code:
public function getAllMessage($offset = 0)
{
$groupCounter = 0;
foreach ($this->groupArray as $currentGroup)
{
$groupCounter++;
$apiUrl = "https://api.vk.com/method/wall.get?owner_id=-". $currentGroup ."&count=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$apiResponse = curl_exec($ch);
$outputArray[$groupCounter] = json_decode($apiResponse, true);
curl_close($ch);
}
print_r($outputArray);
}
Answer the question
In order to leave comments, you need to log in
longer timeout, check $this->groupArray values for validity, it's best to force $outputArray declaration - $outputArray = array();
curl returns false on error.
json_decode from it is useless to do.
And if the argument is in the wrong encoding, it will also be decoded into the void.
Well, the use of $groupCounter demonstrates that this looks like your first PHP script ;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question