0

When running phpdbg on the command line, the value returned from php_sapi_name() is "phpdbg" rather than "cli", which upsets some of my code that checks to ensure the code is being ran on the CLI and not in a web service.

I would rather not change my code to suit a debugger. Is there a way to have phpdbg report the SAPI as "cli" rather than "phpdbg"?

Courtney Miles
  • 3,756
  • 3
  • 29
  • 47

1 Answers1

0

When calling phpdbg you can specify the -S switch to specify any name to report as the SAPI. For example phpdbg -Scli to restore it to "cli".

The official online documentation for phpdbg is at https://phpdbg.room11.org/. However, it seems to be very out of date and does not mention the -S option. To see the current list of options, run phpdbg and use the help options command.

$ phpdbg
prompt> help options

Below are the command line options supported by phpdbg

Command Line Options and Flags
  Option  Example Argument    Description
  -c      -c/my/php.ini       Set php.ini file to load
  -d      -dmemory_limit=4G   Set a php.ini directive
  -n                          Disable default php.ini
  -q                          Suppress welcome banner
  -v                          Enable oplog output
  -b                          Disable colour
  -i      -imy.init           Set .phpdbginit file
  -I                          Ignore default .phpdbginit
  -O      -Omy.oplog          Sets oplog output file
  -r                          Run execution context
  -rr                         Run execution context and quit after execution (not respecting
breakpoints)
  -e                          Generate extended information for debugger/profiler
  -E                          Enable step through eval, careful!
  -s      -s=, -s=foo         Read code to execute from stdin with an optional delimiter
  -S      -Scli               Override SAPI name, careful!
  -l      -l4000              Setup remote console ports
  -a      -a192.168.0.3       Setup remote console bind address
  -x                          Enable xml output (instead of normal text output)
  -p      -p, -p=func, -p*    Output opcodes and quit
  -h                          Print the help overview
  -V                          Print version number
  --      -- arg1 arg2        Use to delimit phpdbg arguments and php $argv; append any $argv argument after it
Courtney Miles
  • 3,756
  • 3
  • 29
  • 47