Service status checker... Is there a more efficient way? I've been working on a website status checker.. However this array that I use has around 30 sites within it, I've noticed it's taking around 6-7 seconds to load it.

I was wondering if there's any kind of way of doing below, but more efficiently.

I have thought of doing the below in a cron, and fetching the stored results from a database.

&lt;?php

function Visit($url){
   $agent = "S3 (SF Service status)";
   $ch=curl_init();
   curl_setopt ($ch, CURLOPT_URL,$url );
   curl_setopt($ch, CURLOPT_USERAGENT, $agent);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch,CURLOPT_VERBOSE,false);
   curl_setopt($ch, CURLOPT_TIMEOUT, 5);
   curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch,CURLOPT_SSLVERSION,3);
   curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
   $page=curl_exec($ch);
   #curl_error($ch);
   #
   #http header response code
   global $httpcode;
   $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

   curl_close($ch);
   if($httpcode&gt;=200 &amp;&amp; $httpcode&lt;=308) return true;
   else return false;
}

$sites = array(
"Name of site" =&gt; "URL",
);
?&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Service Status&lt;/title&gt;
    &lt;link href="static/css/main/main.css" rel="stylesheet" type="css/stylesheet"&gt;
&lt;/head&gt;
&lt;div id="container"&gt;
    &lt;div id="header"&gt;
        &lt;h1&gt;service status&lt;/h1&gt;
    &lt;/div&gt;
    &lt;table width="100%" cellpadding="0" cellspacing="0" colspan="2"&gt;
        &lt;?php
        foreach ($sites as $key =&gt; $value) {
            echo '&lt;tr&gt;';
            if (Visit($value)) {
                echo "&lt;td&gt;&lt;strong&gt;$key&lt;/strong&gt; ($value)&lt;/td&gt;&lt;td class='success'&gt;Available ($httpcode)&lt;/td&gt;";
            } else {
                echo "&lt;td&gt;&lt;strong&gt;$key&lt;/strong&gt; ($value)&lt;/td&gt;&lt;td class='error'&gt;Unavailable ($httpcode)&lt;/td&gt;";
            }
            echo '&lt;/tr&gt;';
        }
        ?&gt;
    &lt;/table&gt;
    &lt;/div&gt;
&lt;/html&gt;


Any recommendations on how parts of this could be done better would be greatly appreciated :)
PHP is not suitable for multi-threading. Though there are some extensions that offer ways of multithreading, they all are, basically, hacks IMO. The best way forward in your case would be: to use a tool that is async by nature, and update the url's as you go along.
Thankfully, such a thing exists, and it goes by the name JavaScript (AJAX calls), here's what I'd do:

foreach ($sites as $key =&gt; $value)
{
    echo '&lt;tr&gt;&lt;td&gt;&lt;strong&gt;',$key, '&lt;/strong&gt; (', $value, ')&lt;/td&gt;',
    '&lt;td class="pending"&gt;&lt;img src="loading.gif"/&gt;&lt;/td&gt;&lt;/tr&gt;';
}


This will present the client with a complete overview of urls (since that's what you say they are), each row showing a gif (optional, of course) of one of those circular loading things This one, for example.
On the page, have script that goes something like this:

window.addEventListener('load',function l()
{
    var pending = document.querySelectorAll('td.pending'),i=0,
    callNext = function(elem)
    {
        var urlMatch = elem.parentNode.cells[0].textContent.match(/\(([^)]+)/)[1],
        xhr = new XMLHttpRequest;
        xhr.open('POST','ajax.php', true);
        xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xhr.onreadystatechange = callback;
        xhr.send('url=' + encodeURI(urlMatch));
    },
    callback = function()
    {
        if (this.readyState === 4 &amp;&amp; this.status === 200)
        {
            var resp = JSON.parse(this.responseText);
            pending[i].setAttribute('class','error');//default error
            if (resp.success)
            {
                pending[i].setAttribute('class','success');
            }
            pending[i].replaceChild(
                document.createTextElement(resp.cellText),
                pending[i].firstChild
            );
            if (++i &lt; pending.length)
            {
                callNext(pending[i]);
            }
        }
    };
    callNext(pending[i]);
    window.removeEventListener('load',l,false);
},false);


Then, the ajax.php script, could just be the Visit function (BTW: please follow the PHP-FIG-coding standards as much as possible, and lower-case that function name). Instead of $url just use:

$url = isset($_POST['url']) &amp;&amp; filter_var($_POST['url'], FILTER_VALIDATE_URL) ? $_POST['url'] : false;
if (!$url)
{
    echo json_encode(array('cellText' =&gt; 'invalid URL'));
    exit;
}
//do curl request
echo json_encode(array('success' =&gt; true, 'cellText' =&gt; 'valid'));//or invalid, depending on curl results


This way, the client gets to see the page quite quickly, and sees it's being updated once every 6~7 seconds, depending on how long the curl request takes to complete.
In addition to that, look into caching extensions, such as APC, and set the cache options for the cUrl requests, too. This usually requires some trial and error to find the right balance...