Question

I have a vast amount of PHP code which interacts with two databases. It's normal state is to run offline within the local network. However, when it is connected to the internet, it connects to a remote database to pull and push data.

Unfortunately, when it's not online, the site hangs trying to connect remotely. I've tried using the checkdnsrr function to see if we are connected to the internet, it's better but still slower than I hope for.

There's far to much to recode here, so anything I can wrap around the PDO database connection statement would be greatly appreciated.

Was it helpful?

Solution

After a bit more research I found you can set the timeout of the request. I've set it to 1sec and it seems to work fine.

However, I still don't believe it's the best solution, 1 second is still a long time to delay a request for.

$DBH = new PDO("mysql:host=$host;dbname=$dbname", $username, $password,array(PDO::ATTR_TIMEOUT => "1"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top