kindrobot
kindrobot

Reputation: 1399

Using phpdbg with the built-in php server?

I really like using the php built in server, and I really like the look of phpdbg. It reminds me of pry in Ruby land. But I've been having trouble getting it to work. Is it possible to run user phpdbg with the build in web server?

E.g., how I would like this to work:

  1. placing phpdbg_break(); in the code
  2. running php -S localhost:8000 in the CLI
  3. loading the page/making the request that executes the code containing the phpdbg_break(); in the browser or through curl
  4. breaking out into a the phpdbg REPL most likely in the same terminal/CLI instance that the built in server was started on

When I try this, I get an error that phpdbg_break(); is an undefined function.

Or else (if the above simply isn't possible), how do you use the "webmocking" that the docs talk about (at the bottom)? How to you make a specific request with a specific URI?

Upvotes: 14

Views: 2526

Answers (2)

Andrei Glingeanu
Andrei Glingeanu

Reputation: 652

I use psysh for this same reason, just because it reminds me of pry. I actually use this snippet of code in place of binding.pry from ruby.

require "path_to_psysh_on_your_local_file_system";
\Psy\Shell::debug(get_defined_vars(), $this);

This is good enough for me. The only problem I'm having with this is:

  1. Can't connect to an existing PHP process running in a CGI, with nginx or apache servers
  2. The built-in PHP server is single threaded and very slow, this drives me crazy sometimes

Other than that, I'm happy with my current workflow. I'd be happy to hear other folks opinions on this.


It even looks like there's some work going on about Remote Debugging, which may solve my issues.

Upvotes: 0

Nico Andrade
Nico Andrade

Reputation: 910

If I understand properly, phpdbg_break is a function provided by the interpreter, and not by any extension. Instead of using the built-in PHP server, you should use the phpdbg server, and simulate a web request. See http://phpdbg.com/docs/mocking-webserver for information on how to mock the request and http://phpdbg.com/docs/simples to know how to run the debugger.

To make a request to the specific URI, I think you need to set $_SERVER['REQUEST_URI'] and optionally $_SERVER['QUERY_STRING'] to point to the URL you want to test. URI will be something like '/path/to/file' and the querystring would be everything between the ? and the # in the URLs (ie ?page=2)

Thanks for pointing me to phpdbg, I didn't know that tool and it seems to be a very good one; I'll be testing it in the next days.

Upvotes: 6

Related Questions