When you use a php crawler, you are prompted to use the cli environment. I checked the current php version information as follows: I printed PHP_SAPI to show how fpm-fcgi can be changed to the cli server environment. linux + nginx is added: can I understand that cli must be in the command line mode? Just in the command...
When using a php crawler, you are prompted to use the cli environment.
I checked the current php version information as follows:
I printPHP_SAPIDisplayfpm-fcgi
How can it becomecli
The server environment is linux + nginx
Supplement: can I understand that cli must be in the command line mode?
I just tested it in the command line.PHP_SAPIOutputcli
Q: Can I implement cli through an http simulated call?
Reply content:
When using a php crawler, you are prompted to use the cli environment.
I checked the current php version information as follows:
I printPHP_SAPIDisplayfpm-fcgi
How can it becomecli
The server environment is linux + nginx
Supplement: can I understand that cli must be in the command line mode?
I just tested it in the command line.PHP_SAPIOutputcli
Q: Can I implement cli through an http simulated call?
CLI = command-line interface = command line interface
You can use popen or proc_open in php-fpm to call php-cli asynchronously to execute a php script, for example:
Example 1 (popen ):
Array ('pipele', 'r'), // stdin (use fwrite to write data to the pipeline) 1 => array ('pipele', 'w '), // stdout (use stream_get_contents to retrieve pipeline output) 2 => array ('pipe', 'w'), // stderr (use stream_get_contents to obtain pipeline output) // 2 => array ('file', '/tmp/err.txt', 'A') // stderr (written to a file), $ pipes, // pipe (stdin/stdout/stderr) '/tmp', // Current PHP process working directory array ('foo' => 'bar') // php. in ini configuration, variables_order = "EGPCS", E indicates $ _ ENV; otherwise, $ _ ENV output is null); // var_dump ($ pipes); // resource of type (stream) if (is_resource ($ proc) {// stdin $ stdin = serialize (array ('time' => time (); fwrite ($ pipes [0], $ stdin); // transmits parameters to the script task. php fclose ($ pipes [0]); // after fclose closes the pipeline, proc_close can exit the sub-process. Otherwise, the register_shutdown_function (function () use ($ pipes, $ proc) will occur) {// event-driven (script end event), asynchronous callback // stdout $ stdout = stream_get_contents ($ pipes [1]); fclose ($ pipes [1]); // stderr $ stderr = stream_get_contents ($ pipes [2]); fclose ($ pipes [2]); // exit code (return the process termination status code, if an error occurs, return-1) $ status = proc_close ($ proc); $ data = array ('stdout' => $ stdout, 'stderr' => $ stderr, 'status' => $ status,); var_export ($ data); // echo json_encode ($ data) ;}}} foo (); // output: array ('stdout' => 'A: 1: {s: 4: "time"; s: 19: "21:26:29 ";}', 'stderr' => '', 'status' => 0 ,)
Cli is the command line, and linux isphpThis command. Php can execute command lines in many ways.execFor synchronous execution of functions, there are methods for asynchronous execution. let's take a look at the document in detail.
Run the script directly on the terminal.