Check if MySql online server is reachable from local application in short period of time with PHP
<p>I have a <strong>local</strong> web application based on <strong>PHP</strong> that uses an <strong>online</strong> Mysql server.</p>

<p>I need to know when I can reach that server (when do I have internet connection, or when the server is shutdown).</p>

<p>I've tried this</p>

<pre><code>$conn = new mysqli('hostname','username','password','db');

if($conn-&gt;connect_error){
    //offline action
}
else{
    //online action
}
</code></pre>

<p>which works but it lasts for about a minute to determine if server is reachable or not.</p>

<p>I was wondering if there is any other solution for this that lasts less than 3 or 4 seconds.</p>