user3592614
user3592614

Reputation: 97

time consuming PHP script and the ways to solve the issue?

I have a PHP registration form that is very time consuming from when the user clicks on the submit button to the point that it will force the server to throw out the following error:

Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.

I have been searching on google for ways to solve this issue and there seems to be a few ways of resolving this. however, I would like to know what is the best way of doing this.

I will explain the steps in the registration form from the when the user clicks the submit button:

step 1- it will checks the mysql database for duplicated data.
step 2- it will create 2 mysql tables with their columns
step 3- it will enter the data passed on by the user into the mysql table.
step 4- it will create a subdomain on my server.
step 5- it will move some files from one folder on my server into the newly created subdomain. there are alot of files but i don't think this should take that long? I need some advise on this please and what is the best way of doing this?
step 6- it will send a confirmation email to the user.

I can post my code but it is very big so I thought it might bore anyone's reading this question.

at the top of my PHP registration page, I have this line of code but this has no affect:

set_time_limit(0);

do you think it is best to use the following code instead?

ini_set('max_execution_time', 300);

any advise to solve this issue would be appreciated.

Thanks

Upvotes: 3

Views: 6879

Answers (2)

Simon E.
Simon E.

Reputation: 58490

This particular error message is generated by the LiteSpeed web server (a faster replacement for Apache). It has a special feature whereby it cancels long-running scripts. To disable this, you need to put the following in your .htaccess file in the root of your site.

RewriteEngine On
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]

Upvotes: 8

Ruslan Bes
Ruslan Bes

Reputation: 2735

It looks pretty much as what hosting servers do.

If you have a process that has some "long" steps then the common practice is to split it and do the "long" steps in the background by a cron job.

So try doing following: let steps 1,2,3 pass as expected, but lock the user account after that and give him/her a message like "Your account will be unlocked soon. We will send you a follow-up email".

After that, write a console script (it can be PHP or any other language) that fetches all the new users that have registered but did not yet passed the whole routine and does the steps 4,5,6 for each of them.

Finally write a cron job that executes the script every minute.

P.S.: The splitting may be different. As @Mark_Baker mentioned it is better first to set time limit to 0 and measure the time for each step.

Upvotes: 3

Related Questions