I'm trying to build a monitor of sorts with the use of cURL to keep track of various different dashboards. The idea is that I load a bunch of URLs which I want to see from a database, and after running this code on a browser window, I'm shown those URLs for a limited time (For example, I'm shown www.dashboard.zopim.com for 10 seconds, then it goes onto another different URL for 30 seconds, and so on, and when it ends, it begins again).
<?php
include_once('connection.php');
$query = "SELECT url, time FROM $tb ORDER BY position";
$result = mysqli_query($connection_, $query);
$rowcount = mysqli_num_rows($result);
$curl_handle = curl_init();
$data = array();
//base array building
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
$data_b = array();
$data_b['curl_handle'] = $curl_handle;
$data_b['url'] = $row[0];
$data_b['time'] = $row[1];
array_push($data, $data_b);
}
for ($i=0; $i < $rowcount; $i++) {
$ch = $data[$i]['curl_handle'];
curl_setopt($ch, CURLOPT_URL, $data[$i]['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$grab = curl_exec($ch);
usleep($data[$i]['time']*100);
curl_close($ch);
return $grab;
}
?>
The problem is that I cannot even get it to start running. As it is right now, it just loads the first page and remains there.
Also, as an off-comment, since I'm quite unfamiliar with cURL as a whole, is there a better way to do this? I've read that there's a multi function that allows me to load multiple URLs asynchronously, but I'm not sure it'd serve me for what I want.