Hello I just recently converted a site to PDO and started having server issues right afterwards. The previous mysql queries were outdated and presented XSS/SQL-injection vulnerabilities, so I had a developer convert it to PDO. The site will run fine for a few hours then users will get errors like: SQLSTATE[HY000] [2002] no such file or directory Code (markup): Warning: PDO::query(): MySQL server has gone away in footer.php on line 50 Code (markup): Warning: PDO::query(): Error reading result set's header in footer.php on line 50 Code (markup): Fatal error: Call to a member function fetchAll() on a non-object in index.php on line 75 Code (markup): At the moment there's not much choice other than to reboot the server and it will run fine for a few more hours. Here are the current settings in my.cnf: [mysqld] default-storage-engine=MyISAM innodb_file_per_table=1 max_allowed_packed=100M max_connections=500 log_error=/var/log/mysql.log log-slow-queries=/var/log/mysql-slow.log [mysqld_safe] log_error=/var/log/mysql.log Code (markup): When I check the server stats, the Ram and CPU are almost at max capacity like 90+ %. Before the site was converted to PDO, it could handle 2-3 times the traffic no problem, but I was told PDO would be more secure and faster. PHP.ini settings: memory_limit = 1024M post_max_size = 8M default_socket_timeout = 60 mysql.connect_timeout = 300 mysql.default_socket= 300 max_execution_time = 1000 max_input_vars = 5000 Need someone to help me get this site running faster, smoother and most importantly STABLE. If you are an expert at server and script optimization please contact me. info @ enterscope.com or PM
You can try changing the MySQL timeout option in your script like below. It seems like you may have some kind of loop or something which is causing the error. Perhaps you could have another programmer review the code. ini_set('mysql.connect_timeout',300); ini_set('default_socket_timeout',300); PHP: Source: http://stackoverflow.com/questions/1644432/mysql-server-has-gone-away-in-exactly-60-seconds
Increasing the timeout is not the solution. This is a poorly written script that runs in a loop and crashes, most likely it never ends the processes it creates. Contact me if you need any assistance.
It looks like it was a problem with hosting multiple sites on the same VPS. Another site's cron jobs were overloading the resources at certain times.