With below code i am trying to run script in background. but when hit url in browser then browser is waiting is completion and after this success message is coming. I do not want to hang on browser and do not want to wait for its complete.
Is there any want i can get Process ID (Linux PID) as output when process start. We can say on demand i want to create Process same as Cron job does. but i do not want to setup a Cron job. Because i have 1000 users and each user want to do crawl on demand.
My prev question which is related to this.
How to create background process in PHP
Code on PasteBin: http://pastebin.com/6FkS9ZYx
component:
/
* @component to write sample script which will pass to backend jobs
*
*/
App::uses('Component', 'Controller');
class BackgroundScriptComponent extends Component {
public function crawllUrls($crawling) { // Passing 500 urls to crawl
for ($i = 0; $i < $Counter; $i++) {
/*
Internal code which is running perfect using browser hit
*/
}
}
}
/* @component to write sample script which will pass to backend jobs */
Controller:
class ScriptController extends AppController {
public $components = array('BackgroundScript');
public function CreateBackendProcess() {
$this->layout = false;
$this->autoRender = false;
$arrOfUrls = array('500 url there in this array');
//echo $this->BackgroundScript->crawllUrls($crawling); // This line having Component method call. I do not want to call this as same as.. It should call from CLI
$cmd = ""; //what should come in this $cmd to calls BackgroundScript's crawllUrls() method component which will pass to exec()
exec($cmd, $pid);
echo "<br />Script Running with process id " . json_encode($pid); //I will save this PS ID to database
exit;
}
}