I'm fairly new to php, and I wanted to create a form where if they pressed a button, a loop would start, and it would only stop when they either exited the page, or hit a stop button. I'm not sure how to go about doing this, any advice/help?
if(preg_match_all('/([0-9]+)(.*?)php (201)/', $running_ps, $a_matches)) {//identify the proces you need
foreach ($a_matches[1] as $key => $value) {
$a_running_proc = $value;
}
}
if (isset($_REQUEST['action'])) {
if($_REQUEST['action'] == '0' ) {
//stop the process
proc_close(proc_open('kill '. $a_running_proc, array(), $foo));//kill the process
}
else
{
//do whatever you want to do
//then start the process again
proc_close(proc_open("php [script_file_name] 201 &", array(), $foo));//run the process in background
if(preg_match_all('/([0-9]+)(.*?)php (201)/', $running_ps, $a_matches)) {//identify the proces you need
foreach ($a_matches[1] as $key => $value) {
$a_running_proc = $value;
}
}
if (isset($_REQUEST['action'])) {
if($_REQUEST['action'] == '0' ) {
//stop the process
proc_close(proc_open('kill '. $a_running_proc, array(), $foo));//kill the process
}
else
{
//do whatever you want to do
//then start the process again
proc_close(proc_open("php [script_file_name] 201 &", array(), $foo));//run the process in background
Yes, it sends until someone stops it, but be carefull: IF YOU CLOSE THE BROWSER, YOU DON'T STOP THE PROCESS
As about delays, it doesn't have any delay...send the email, then runs the process again.
If you want to add a delay, you can put the script to sleep by doing this:
PHP Code:
else { $i = 0; echo $i; sleep([int_value]); proc_close(proc_open("php [script_file_name] 201 &", array(), $foo));//run the process in background
Yet...you won't be able to see that this works by echoing, because it is a process, so it won't refresh your web page...you should write those values into a file or a DB.
Yet...you won't be able to see that this works by echoing, because it is a process, so it won't refresh your web page...you should write those values into a file or a DB.
How would i check if the script is already running? As in if i want a field on.the first webpage that says "Script status: Running/not running"
if(preg_match_all('/([0-9]+)(.*?)php (201)/', $running_ps, $a_matches)) {//identify the proces you need foreach ($a_matches[1] as $key => $value) { $a_running_proc = $value; } } if (isset($_REQUEST['action'])) {
if($_REQUEST['action'] == '0' ) {
//stop the process proc_close(proc_open('kill '. $a_running_proc, array(), $foo));//kill the process echo "process stopped"; require('html_file_name'); } else { //do whatever you want to do //then start the process again proc_close(proc_open("php [script_file_name] 201 &", array(), $foo));//run the process in background echo "process running";//print this text before showing buttons require('html_file_name');//this will show those buttons
but if you do this, there is no need to change the php as described in the post above...you could just call header('Location:[button_file]'); instead of echo and require()
Bookmarks