I am making a script to bulk import csv data into a mysql DB table. I am looping through the data and checking if the value already exist in database. If not then insert it into the table.
But the script is giving 504 gateway timeout error. I tried increasing the max_execution_time but nothing is working, the script timeout occurs in around 7-9 minutes.
I tried increasing the timeout in the cPanel and also using the below code
ini_set('max_execution_time', 1800);
ini_set('default_socket_timeout', 1800);
But nothing is working, prior thanks to any help.
PHP version is 7.3
2
Answers
All the webservers usually have a separate timeout as well than php like Apache and IIS around 6-7 mins by default. You need to check which software your host is running and check its documentation. Although usually you can’t change these setting only the server owners (I’m guessing you are renting a server/space). But first it’s worth a try to
echo ini_get('max_execution_time');
after you set them to see if it changed anything or has been overridden by the server (on shared host there might be a ‘hard cap’ which you can’t increase further.You should try MYSQL TRANSACTION to insert csv records. Start TRANSACTION before insert operation start and COMMIT TRANSACTION after all process end. Here is small example which will help you.
Thankyou.