Link to home
Start Free TrialLog in
Avatar of WhiteyD
WhiteyD

asked on

Database connection timeout when accessing via PHP & IIS on Win2003 Server

We are running MySql 4.1 and PHP 5.0.4 and IIS 6 on a Win 2003 Server.
The mysql_connect() function seems to be timing out at intermitant intervals.
We can run a number of sql queries for sometimes 10 to 15 mins, then mysql_connect() returns false and we get a #256 error.
We have set the IIS timeouts very high, and the PHP session timeouts to many hours.
Whenever the connection fails we can still use the same My Sql user ID in a mysql command line session and access the database.
We then wait for say 10 mins, and rerun the PHP scripts and it starts working again. Then the problem occurs all over.
Sometimes it only takes a few queries before it fails.

We are using sessions in PHP, and there is a session_start() call at the top of each PHP script.

Any clues would be really really appreciated.
thanks.
Avatar of todd_farmer
todd_farmer
Flag of United States of America image

What is the actual error message you get?  Error code #256 isn't listed in the MySQL error codes:

C:\Documents and Settings\todd>perror 256
Illegal error code: 256
Avatar of WhiteyD
WhiteyD

ASKER

Here is the script code.
Simply, mysql_connect() is returning false, and we are firing trigger_error().


function db_connect($dbname)
{
   global $dbconnect, $dbhost, $dbusername, $dbuserpass;

   if (!$dbconnect)
     $dbconnect = mysql_connect($dbhost, $dbusername, $dbuserpass);

   if (!$dbconnect)
   {
      trigger_error("Cannot connect to MySQL database", E_USER_ERROR);
      return 0;
   }
   elseif (!mysql_select_db($dbname))
   {
      trigger_error("Cannot find database: $dbname", E_USER_ERROR);
      return 0;
   }
   else
   {
      return $dbconnect;
   }

}
Can you change this:

  if (!$dbconnect)
   {
      trigger_error("Cannot connect to MySQL database", E_USER_ERROR);
      return 0;
   }


to this:

  if (!$dbconnect)
   {
      trigger_error("Cannot connect to MySQL database:".mysql_error(), E_USER_ERROR);
      return 0;
   }
Avatar of WhiteyD

ASKER

Todd,
Sorry for the delay in the response.
Tried your suggestion.
The error number is 10060. "Cannot connect to MySQL server on blahblah.com.au"
ASKER CERTIFIED SOLUTION
Avatar of todd_farmer
todd_farmer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WhiteyD

ASKER

Thanks for the info Todd.
We will most definately check out the firewall.
We are also in the process of building a very clean vanilla test server (with no firewall) to try this out.
We only have limited access to the clients site, so wont be able to check the firewall for a few days.
Appreciate your suggestions.
Will update you as soon as we can check out the firewall or run the test server.