Both php_sapi_name() and the PHP_SAPI constant give the same value. But calling the method is less efficient that simply referencing the constant.
php_sapi_name()
PHP_SAPI
if (php_sapi_name() == 'test') { ... }
if (PHP_SAPI == 'test') { ... }