<?php
include 'includes/config.php';
function do_curl($start_index, $stop_index) {
// Do query here to get all pages with ids between start index and stop index
$query = "SELECT * FROM fanpages WHERE idnum >= $start_index and idnum <= $stop_index";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$fanpages_query[] = 'http://graph.facebook.com/'.$row['page_id'];
}
return $fanpages_query;
}
$fanpages = do_curl($_GET['start_index'], $_GET['stop_index']);
$fanpages_count = count($fanpages);
$curl_arr = array();
$master = curl_multi_init();
for($i = 0; $i < $fanpages_count; $i++)
{
$url = $fanpages[$i];
$curl_arr[$i] = curl_init($url);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($master, $curl_arr[$i]);
}
do {
curl_multi_exec($master,$running);
} while($running > 0);
echo "results: <br>";
for($i = 0; $i < $fanpages_count; $i++)
{
$results = json_decode(curl_multi_getcontent($curl_arr[$i]));
echo("Page Name: ".($results->name)."<br>"."Likes: ".($results->likes)."<br>"."ID: ".($results->id)."<br><br>");
}
echo 'done';
?>
And like you can see almost everything works, the only problem is with the Array’s, I asked a question related to this like two hours ago but the answer that I got doesn’t work for me. So the problem is that the combination of do_curl and the while in it with $fanpages arrays list is not working. every time I’m trying to run the script i get the proper number of pages, proper number of data but it throws me this error:
Notice: Trying to get property of non-object in C:\xampp\htdocs\curltest.php on line 46
Notice: Trying to get property of non-object in C:\xampp\htdocs\curltest.php on line 46
Notice: Trying to get property of non-object in C:\xampp\htdocs\curltest.php on line 46
My bet is that the arrays aren’t parsed like they need to be | $fanpages = array(‘http://graph.facebook.com/1111111’, ‘http://graph.facebook.com/222222222’, ‘http://graph.facebook.com/333333333’); | because if I write them manually everything works.
EDIT: There was a script error on:
$fanpages_query[] = '\'http://graph.facebook.com/'.$row['page_id']."'";
and i just removed the \’ and now its throwing:
Notice: Undefined property: stdClass::$name in C:\xampp\htdocs\curltest.php on line 48
After adding var_dump:
object(stdClass)#1 (1) { ["error"]=> object(stdClass)#2 (2) { ["type"]=> string(20) "GraphMethodException" ["message"]=> string(24) "Unsupported get request." } } string(78) "{"error":{"type":"GraphMethodException","message":"Unsupported get request."}}" NULL
Notice: Undefined property: stdClass::$name in C:\xampp\htdocs\curltest.php on line 48
The JSON decoding is failing. Change it to this and post the results so we can get some more info:
EDIT 1
According to the comments you aren’t getting any data back. Is there a reason you aren’t using code like that which is provided in the
curl_multi_exec()manual page?