skip to Main Content

System Spec:
VPS running Windows Server 2008 R2 SP1
64-bit dual core 2.39GHz VCPU
2GB RAM
Parallels Plesk for Windows 10.4.4
IIS 7.5
PHP 5.2.17
MySQL 5.1.56

I have a PHP script to loop through a static file and import each line as a row in MySQL. This works fine if the file is split into several thousand lines at a time, but this creates a lot of manual effort.

The whole file contains around 160,000 lines to be imported. The script currently connects to the database via mysql_connect / mysql_select_db, processes the loop with mysql_query, and disconnects at the end of the loop. However, at any point between around 55 seconds – 1 min 35 seconds, the client browser returns a 500 Internal Server Error page, which contains no useful diagnostic info.

I have tried increasing the max connection times of MySQL, PHP, IIS and even the max user sockets for winsock, to no avail.

I tried performing a connect / disconnect to MySQL for each insert query, but this caused thousands of connections to the server which were then stuck in a “TIME_WAIT” state, and returned a “could not connect to server” error, presumably due to insufficient sockets remaining. I have also tried both the mysql and mysqli extensions.

I have looked through all the logs I can find for IIS and MySQL, but cannot see anything that would help with finding the cause.

The last two attempts inserted 33,979 and 78,173 rows respectively.

Can anyone offer any assistance?

Thanks.

** UPDATE **

This must be an IIS issue. I have converted the script to run via command-line PHP and it processes the whole file with no issues.

2

Answers


  1. Sounds like a IIS issue. Most I have found reside in the Web.config file. I would take a look at that and make sure the settings are correct and the syntax is correct. Many a time I forgot to close my tags and received a 500 error.

    Login or Signup to reply.
  2. Use LOAD DATA INFILE instead of trying to do the INSERTs via PHP. It will run a lot faster, thereby avoiding the 500 error.

    Do not even consider using the mysql_* interface. Switch to mysqli or PDO. It is deprecated and gone in the latest PHP release.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search