PHP CLI: Hidden Process: Difference between revisions

m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
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 14: Line 13:
|-
|-
|'''''Run.bat''''' - No changes required
|'''''Run.bat''''' - No changes required
|-valign="top"
|-valign="top"
|
|
<pre>
<pre>
TITLE CLI TEST BAT
TITLE CLI TEST BAT
COLOR B0
COLOR B0
Line 25: Line 24:
echo.
echo.
:pause
:pause
&lt;/pre&gt;
</pre>
|
|
&amp;nbsp;
&nbsp;
|valign=&quot;middle&quot;|
|valign="middle"|
This batch file runs test script test1.php
This batch file runs test script test1.php


Line 43: Line 42:
|-
|-
|'''test_1.php'''
|'''test_1.php'''
|-valign=&quot;middle&quot;
|-valign="middle"
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php
   echo &quot; \nScript test_1.php\n\n This will run a hidden process\n&quot;;
   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
?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
&amp;nbsp;
&nbsp;
|valign=&quot;middle&quot;|
|valign="middle"|
This script runs a hidden process
This script runs a hidden process


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


$cmd = &quot;start usr\local\php\php.exe -n test_3.php&quot;;
$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
?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
&amp;nbsp;
&nbsp;
|valign=&quot;middle&quot;|
|valign="middle"|
This script is a hidden process
This script is a hidden process


Line 104: Line 103:
|-
|-
|'''''test_3.php'''''
|'''''test_3.php'''''
|-valign=&quot;top&quot;
|-valign="top"
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php
$a=0;
$a=0;
while($a !=10){
while($a !=10){
   usleep(1000000);  
   usleep(1000000);  
  echo &quot; &quot;.$a.&quot;\n&quot;;
  echo " ".$a."\n";
  $a=$a+1;
  $a=$a+1;
}
}
exit(0); // Script ran OK
exit(0); // Script ran OK
?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
&amp;nbsp;
&nbsp;
|valign=&quot;middle&quot;|
|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 155: Line 154:


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
&lt;pre&gt;
<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';
&lt;/pre&gt;
</pre>
Run the batch file (double click on Run.bat).
Run the batch file (double click on Run.bat).


Line 171: Line 170:
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  
&lt;pre&gt;
<pre>
&lt;?php
<?php
   echo &quot; \n Script test_1.php\n\n This will run a hidden process\n&quot;;
   echo " \n Script test_1.php\n\n This will run a hidden process\n";
   usleep(2000000);
   usleep(2000000);
   $cmd = &quot;start usr\local\php\php-win.exe -n test_2.php&quot;;
   $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
?&gt;
?>
&lt;/pre&gt;  
</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.