i need help
i need help

Reputation: 2386

HOW TO make test.php continue with rest of coding without waiting for a function to complete task?

This is the case. At test.php, I have a function dotask(a,b,c,d);

This function need to do task that need 2-4 minutes to complete. Task including insert new record into db, curl call to other url to do task and etc.

However, I want test.php to: Just make sure dotask(a,b,c,d) is called, no need to wait until task completed then only return and continue with the remaining code at bottom.

Reason: test.php is a thank you page. I can't expect the user to wait few minutes for the task to be completed. Because I need to show thank you messages etc at that page to user.

What can I do?

Upvotes: 1

Views: 2911

Answers (2)

i need help
i need help

Reputation: 2386

I seen a few solutions here that require you to pass in the page that you want to run, eg: BackgroundProcess::fork('process_user.php');

But my case is at test.php, I have dotask(a,b,c,d) I need to pass in parameters from this site to continue the work.

So should I just pass in this few parameter into a new dbtable call pendingprocess, then at process_user.php , I read from database and continue the task instead?

I can't embed parameter into taskpage.php right...

Another solution I can think of is at thankyou.php I do a body onload ajax call by passing in parameter to process_user.php to perform task. Anyone can advice whether this is a good way? Will the process stop executing when user click STOP at browser? What if they go to refresh the browser.

Upvotes: 0

deceze
deceze

Reputation: 522005

You can't fork a process in PHP without a lot of hackery. I'd recommend using a queue and worker pattern instead. See this answer: PHP- Need a cron for back site processing on user signup... (or fork process)

Upvotes: 2

Related Questions