Re: database connection timeout
| From: | Martin Norland | Date: | Thu, 24 Mar 2005 14:48:31 +0000 |
| Subject: | Re: database connection timeout | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39023@lists.php.net to get a copy of this message | ||
Juffermans, Jos wrote:
Hi, [snip]Hello, again. I'm afraid phrasing a question multiple ways over a course of days tends not to have much success. In an effort to avoid populating google with just the question, I will give to you what I would try. ( please note the irony of this .... now. )
I'm trying to connect to an Oracle database (using ocilogon) which is in a different country and connected to our serverfarm via a VPN (the database has no public access). Unfortunately the VPN or the database is not always available. In those cases I will present the visitor with a page explaining that the service is unavailable. [snip]Is it that it's not always available, or that it needs time to 'come back up'. You may want to try running some random low-traffic application over it to make sure it remains running. Some simple SNMP protocol or even simpler just connect to a remote GKrellM. Heck, a ssh connection with top running would do - just something that is constantly transmitting a trickle of data.
My problem is that ocilogon takes a long time to return control if the connection cannot be established - often even more than 30 seconds. I've learned that if a connection can be established it'll happen in only a few seconds (usually within 1 second) and am convinced that if the connection is not established in eg 5 seconds, there is no point in waiting another eg 30 seconds. How can I tell ocilogon to timeout after eg 5 seconds (like you can with fsockopen)? [snip]I can't claim whether or not it will work since I don't have an Oracle server handy, so I will merely name functions and talk a bunch. Essentially, you want ocilogon (complex network function to login to a networked Oracle [in this case] server) to timeout just like fsockopen (fairly simple function to open a socket, including network resources). My suggestion is to try connecting using fsockopen, with the timeout. If it successfully connects - chances are, the majority of the time, your ocilogon that follows will work as well. Unfortunately, the stream_set_* functions rely on a valid stream resource, so they won't work with ocilogon (if there was any chance they would). That would have been a nice route to go otherwise. Another dirty little trick you might use is running the ocilogon in a separate script and making use of set_time_limit() to make sure it doesn't run too long. Just be sure not to set_time_limit() for your whole set of scripts, unless you really want them to abort after the 5 or 10 second limit you're setting ocilogon (unlikely). cheers, -- - Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.