On my website, I have the function of loading data feeds by users. These data channels typically have over 30,000 records. And each entry must go through a complex verification process. Thus, to complete this task, it will take more than 1 hour to process the chips. This long-term process is inevitable.
Here these channels are uploaded by a public user. File size less than 5 MB text file. Therefore, we do not want to provide FTP access, nor do we want to provide command line access to these users. Only we prefer to provide web access for downloading feeds. And we must process the feed immediately after they are downloaded. And after processing, we also need to send them a mail report.
Now the problem is that web pages with long jobs throw some proxy server problem into many network jobs (since it takes 1 hour to answer). This is a problem with most client network configurations.
I need a way to run a PHP script after loading the feed. And that the script should work in the background, at the same time, correctly complete the page loading without delaying the client.
I will make a background for processing data and sending mail to the client after the process is completed. The Cron tab is not available here, as the client can only use this feature several times a month and in an unforeseen time range.
If there is a way to run a PHP script in the background, but through web access, let me know.
Sample script to simplify the requirement
Assume this example and help me modify this script to achieve the result. I have two PHP scripts "thread.php and createfile.php". A file called "thread.php" will be opened by the client through a web browser. This script should execute the script "createfile.php". But the answer will take 20 seconds. But we want it to work in the background. And print immediately in the browser.
Below is the code for the sample scripts.
createfile.php ( http://sugunan.net/demo/createfile.php )
<?php sleep(20); @unlink("phpfile.txt"); $myfile = fopen("phpfile.txt", "w") or die("Unable to open file!"); $txt = date("h:i:s")."\n"; fwrite($myfile, $txt); fclose($myfile); mail("someone@example.com","Background process","Process completed"); ?>
the created file is displayed on the web url: http://sugunan.net/demo/phpfile.txt
thread.php ( http://sugunan.net/demo/thread.php )
<pre> <?php echo "Script start at: " . date('h:i:s') . "\n"; include("createfile.php");
This will give the following result with a delay to the sleep() function.
Script start at: 02:53: 27
Script end at: 02:53: 47
Is there any way to execute "createfile.php" without the include() method. And to avoid a 20 second sleep delay while processing "createfile.php" in the background?
Please think that I want to avoid client side latency and want to send it immediately to the browser.