I want to create background process in PHP
I am trying all these with AJAX call on client side and PHP on server side..
Actually i am scrapping lot of urls. To do this, I am listing all the scrap url in text area and submitting form using POST method. The form action will catch the POST data and pass to background script. As i can pass lot of urls, it could be 1000 , just because i want to run script in background on demand and when it complete return me output in a file or database. (Write Process id in file or db, i can do)
I do not want to setup a back end cron job for this which will run after 15 min.
The issue coming with PHP code which we generally used to parse is Until my script execution did not complete i can't close browser or change page. But i want to change page and also i can browser but script should run in background.
My understanding is in this case:
- I have a form in page, on form submit, i will call on a PHP script which will run in Background.
- Background process started and running ....running ....running .....running......
- I want to got back process id with which Process id Background process started and previous background process running ....running ....running .....running ..........
It is behaving like other languages Channel if i am right..
i come to solution with PHP Code: I am assuming this below script will work as i want or i need to find another way ?
$cmd = "php test.php > testoutput.php 2>&1 & echo $!";
exec($cmd, $pid);
echo "Script Running with ".$pid;
exit;