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.
WhiteyDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

todd_farmerCommented:
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
WhiteyDAuthor Commented:
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;
   }

}
todd_farmerCommented:
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;
   }
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

WhiteyDAuthor Commented:
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"
todd_farmerCommented:
That seems to indicate that perhaps there is a firewall between the client and server that is not allowing traffic, or that the server itself is configured to not respond to TCP/IP.  What information do you have regarding whether or not you should be able to connect to port 3306 on the server machine from the client?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WhiteyDAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.