PHP CLI: Hidden Process: Difference between revisions

Jump to navigation Jump to search
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...)
 
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="top"
|-valign="top"
|
|
<pre>
&lt;pre&gt;
TITLE CLI TEST BAT
TITLE CLI TEST BAT
COLOR B0
COLOR B0
Line 24: Line 25:
echo.
echo.
:pause
:pause
</pre>
&lt;/pre&gt;
|
|
&nbsp;
&amp;nbsp;
|valign="middle"|
|valign=&quot;middle&quot;|
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="middle"
|-valign=&quot;middle&quot;
|
|
<pre>
&lt;pre&gt;
<?php
&lt;?php
   echo " \nScript test_1.php\n\n This will run a hidden process\n";
   echo &quot; \nScript test_1.php\n\n This will run a hidden process\n&quot;;
   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
?>
?&gt;
</pre>
&lt;/pre&gt;
|
|
&nbsp;
&amp;nbsp;
|valign="middle"|
|valign=&quot;middle&quot;|
This script runs a hidden process
This script runs a hidden process


Line 68: Line 69:
|-
|-
|'''test_2.php'''
|'''test_2.php'''
|-valign="middle"
|-valign=&quot;middle&quot;
|
|
<pre>
&lt;pre&gt;
<?php
&lt;?php
   echo " \n Script test_2.php\n\n This is a hidden process!!\n";
   echo &quot; \n Script test_2.php\n\n This is a hidden process!!\n&quot;;
   echo " It delays for 10 seconds and runs script test_3.php\n";
   echo &quot; It delays for 10 seconds and runs script test_3.php\n&quot;;


$a=0;
$a=0;
while($a !=10){
while($a !=10){
  usleep(1000000);  
  usleep(1000000);  
  echo " ".$a."\n";
  echo &quot; &quot;.$a.&quot;\n&quot;;
  $a=$a+1;
  $a=$a+1;
}
}


$cmd = "start usr\local\php\php.exe -n test_3.php";
$cmd = &quot;start usr\local\php\php.exe -n test_3.php&quot;;
pclose(popen($cmd,'r'));    // Run detached process   
pclose(popen($cmd,'r'));    // Run detached process   
exit(0); // Script ran OK
exit(0); // Script ran OK
?>
?&gt;
</pre>
&lt;/pre&gt;
|
|
&nbsp;
&amp;nbsp;
|valign="middle"|
|valign=&quot;middle&quot;|
This script is a hidden process
This script is a hidden process


Line 103: Line 104:
|-
|-
|'''''test_3.php'''''
|'''''test_3.php'''''
|-valign="top"
|-valign=&quot;top&quot;
|
|
<pre>
&lt;pre&gt;
<?php
&lt;?php
$a=0;
$a=0;
while($a !=10){
while($a !=10){
   usleep(1000000);  
   usleep(1000000);  
  echo " ".$a."\n";
  echo &quot; &quot;.$a.&quot;\n&quot;;
  $a=$a+1;
  $a=$a+1;
}
}
exit(0); // Script ran OK
exit(0); // Script ran OK
?>
?&gt;
</pre>
&lt;/pre&gt;
|
|
&nbsp;
&amp;nbsp;
|valign="middle"|
|valign=&quot;middle&quot;|
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>
&lt;pre&gt;
   $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>
&lt;/pre&gt;
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>
&lt;pre&gt;
<?php
&lt;?php
   echo " \n Script test_1.php\n\n This will run a hidden process\n";
   echo &quot; \n Script test_1.php\n\n This will run a hidden process\n&quot;;
   usleep(2000000);
   usleep(2000000);
   $cmd = "start usr\local\php\php-win.exe -n test_2.php";
   $cmd = &quot;start usr\local\php\php-win.exe -n test_2.php&quot;;
   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
?>
?&gt;
</pre>  
&lt;/pre&gt;  
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.


322

edits

Navigation menu