문제

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.

도움이 되었습니까?

해결책

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"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top