Use this package to determine what type of interface your PHP app is using to run.
The recommended way of including this package in your project is via Composer
$ composer require natokpe/php-interface
To use the package, you can simply do something like this
use Natokpe\PhpInterface\PhpInterface;
require_once __DIR__ . '/vendor/autoload.php';
$interface = new PhpInterface;
echo $interface->which(); // will print 'cli' if PHP is using CLI to run or 'web' if PHP is run from web
You can also use either of the isCli()
or isWeb()
methods to check
if ( $interface->isCli() ) {
echo 'cli'; // will print 'cli' if PHP is using CLI to run
}
if ( $interface->isWeb() ) {
echo 'web'; // will print 'web' if PHP is run from web
}
Additionally, you may want to know if PHP is using a CGI based interface. Use the isCgi()
method to check.
if ( $interface->isCgi() ) {
echo 'cgi'; // will print 'cgi' if PHP is using a CGI based interface to run
}
You can use PhpInterface without having to instantiate the class via the getType()
static method, like this
echo PhpInterface::getType(); // will print either 'cli' or 'web' depending on which type of interface PHP is using
The getType()
static method is similar to which()
method.
That's it! I hope you like it and find it useful.
Thank you.