Pausing PHP process via command line -


i running via command line. when loop running, there way can pause execution of code? ideal case press key pause , key resume. if don't press pause key loop continues until $i == 1000

<?php  echo "how long should code sleep between increments?\n"; echo ">> ";  $sleep = trim(fgets(stdin));  ($i = 1; $i <= 1000; $i++) {     echo "$i\n";     sleep($sleep); } 

this heavily simplified example of actual need code.

i don't sure code best solution or not work.

function checkresume() {     $r = false;      while (!$r) {         if (fgets(stdin) == "r") {             $r = true;         }     }  }  function checkpause() {     $input = fgets(stdin);     if (!empty($input) && $input == "p") {         return true;     }     return false;  }  echo "how long should code sleep between increments?\n"; echo ">> ";  $sleep = trim(fgets(stdin));  echo "\nstart ...\n";  stream_set_blocking(stdin, false); ($i = 1; $i <= 1000; $i++) {     if (checkpause()) {         echo "wait resume \n";         checkresume();     }      echo "$i\n";     sleep($sleep); } 

hope help.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -