Reputation: 19118
The title is quiet straightforward. I have to know on server side if the script called through HTTP request or by command line. I could examine the $_SERVER['argv']
or $_SERVER['argc']
.
What is the pragmatic way to do that?
Upvotes: 11
Views: 4303
Reputation: 48284
https://www.php.net/manual/en/function.php-sapi-name.php
<?php
echo PHP_SAPI;
echo php_sapi_name();
?>
Upvotes: 14
Reputation: 32878
But you have to send the data through http (tcp) anyway no matter if the script is called from cli or from a browser
Upvotes: 0
Reputation: 61547
Possibly checking if no $_SERVER['HTTP_HOST']
is set? Because I believe that variable is populated through the Request Headers sent to a file on exection, and the command line probably doesn't send headers.
Upvotes: 1