PHP CLI: Hidden Process: Difference between revisions
no edit summary
(New page: {{Uc nav PHP CLI}} '''''PHP CLI hidden processes''''' On the previous page I covered detaching processes in certain situation that process may remain visible. For example if a process runs...) |
Upazixorys (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
=[http://usuzezyjiza.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]= | |||
{{Uc nav PHP CLI}} | {{Uc nav PHP CLI}} | ||
'''''PHP CLI hidden processes''''' | '''''PHP CLI hidden processes''''' | ||
Line 13: | Line 14: | ||
|- | |- | ||
|'''''Run.bat''''' - No changes required | |'''''Run.bat''''' - No changes required | ||
|-valign= | |-valign="top" | ||
| | | | ||
<pre> | |||
TITLE CLI TEST BAT | TITLE CLI TEST BAT | ||
COLOR B0 | COLOR B0 | ||
Line 24: | Line 25: | ||
echo. | echo. | ||
:pause | :pause | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
|valign= | |valign="middle"| | ||
This batch file runs test script test1.php | This batch file runs test script test1.php | ||
Line 42: | Line 43: | ||
|- | |- | ||
|'''test_1.php''' | |'''test_1.php''' | ||
|-valign= | |-valign="middle" | ||
| | | | ||
<pre> | |||
<?php | |||
echo | echo " \nScript test_1.php\n\n This will run a hidden process\n"; | ||
usleep(2000000); | usleep(2000000); | ||
$cmd = 'start usr\local\php\php.exe -n test_2.php'; | $cmd = 'start usr\local\php\php.exe -n test_2.php'; | ||
pclose(popen($cmd,'r')); // Run detached process | pclose(popen($cmd,'r')); // Run detached process | ||
exit(0); // Script ran OK | exit(0); // Script ran OK | ||
? | ?> | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
|valign= | |valign="middle"| | ||
This script runs a hidden process | This script runs a hidden process | ||
Line 68: | Line 69: | ||
|- | |- | ||
|'''test_2.php''' | |'''test_2.php''' | ||
|-valign= | |-valign="middle" | ||
| | | | ||
<pre> | |||
<?php | |||
echo | echo " \n Script test_2.php\n\n This is a hidden process!!\n"; | ||
echo | echo " It delays for 10 seconds and runs script test_3.php\n"; | ||
$a=0; | $a=0; | ||
while($a !=10){ | while($a !=10){ | ||
usleep(1000000); | usleep(1000000); | ||
echo | echo " ".$a."\n"; | ||
$a=$a+1; | $a=$a+1; | ||
} | } | ||
$cmd = | $cmd = "start usr\local\php\php.exe -n test_3.php"; | ||
pclose(popen($cmd,'r')); // Run detached process | pclose(popen($cmd,'r')); // Run detached process | ||
exit(0); // Script ran OK | exit(0); // Script ran OK | ||
? | ?> | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
|valign= | |valign="middle"| | ||
This script is a hidden process | This script is a hidden process | ||
Line 103: | Line 104: | ||
|- | |- | ||
|'''''test_3.php''''' | |'''''test_3.php''''' | ||
|-valign= | |-valign="top" | ||
| | | | ||
<pre> | |||
<?php | |||
$a=0; | $a=0; | ||
while($a !=10){ | while($a !=10){ | ||
usleep(1000000); | usleep(1000000); | ||
echo | echo " ".$a."\n"; | ||
$a=$a+1; | $a=$a+1; | ||
} | } | ||
exit(0); // Script ran OK | exit(0); // Script ran OK | ||
? | ?> | ||
</pre> | |||
| | | | ||
| &nbsp; | ||
|valign= | |valign="middle"| | ||
Purpose of this script is to provide visual feedback to show something is happening. | Purpose of this script is to provide visual feedback to show something is happening. | ||
Line 154: | Line 155: | ||
Add '''/b''' to start as shown below this runs a script in the background | Add '''/b''' to start as shown below this runs a script in the background | ||
<pre> | |||
$cmd = 'start /b usr\local\php\php.exe -n test_2.php'; | $cmd = 'start /b usr\local\php\php.exe -n test_2.php'; | ||
</pre> | |||
Run the batch file (double click on Run.bat). | Run the batch file (double click on Run.bat). | ||
Line 170: | Line 171: | ||
Edit file test_1.php | Edit file test_1.php | ||
There are two changes, remove the '''/b''' and replace '''php.exe''' with '''php-win.exe''' this runs a script in the background | There are two changes, remove the '''/b''' and replace '''php.exe''' with '''php-win.exe''' this runs a script in the background | ||
<pre> | |||
<?php | |||
echo | echo " \n Script test_1.php\n\n This will run a hidden process\n"; | ||
usleep(2000000); | usleep(2000000); | ||
$cmd = | $cmd = "start usr\local\php\php-win.exe -n test_2.php"; | ||
pclose(popen($cmd,'r')); // Start a new forked process close file pointer | pclose(popen($cmd,'r')); // Start a new forked process close file pointer | ||
exit(0); // Script ran OK | exit(0); // Script ran OK | ||
? | ?> | ||
</pre> | |||
Run the batch file (double click on Run.bat). The second script is run in the background, after a delay (about ten seconds) '''test_3.php''' is displayed as expected. | Run the batch file (double click on Run.bat). The second script is run in the background, after a delay (about ten seconds) '''test_3.php''' is displayed as expected. | ||