mpen
mpen

Reputation: 283313

How to check if PHP is running under built-in server?

From PHP, how can I check if my server was started with something like:

php -S localhost:8080 -t public index.php

? I need some special logic to serve static files during development. Nginx won't need this code, so I want to put in a check.

Upvotes: 1

Views: 240

Answers (1)

user149341
user149341

Reputation:

By calling php_sapi_name(). It'll return "cli-server" when running under the built-in server, and another value (probably "cgi-fcgi" or "fpm-fcgi", depending on your setup) when running from nginx.

Upvotes: 2

Related Questions