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.
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.
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;
}
}
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;
}
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;
}
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"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
C:\Documents and Settings\todd>perror 256
Illegal error code: 256