Remote Debugging PHP Command Line Scripts with Zend? - php

I'm using Zend Studio to do remote debugging of my php scripts on a dev server. It works great for web code, but can I make it work with command line scripts?
I have several helper apps to make my application run. It would be really useful to fire up the remote debugger through command line instead of a web browser so I can test these out.
I assume it's possible, since I think Zend is using xdebug to talk to Eclipse. Apparently, it adds some parameters to the request to wake the Zend code up on a request. I'm guessing I'd need to tap into that?
UPDATE
I ended up using xdebug with protoeditor over X to do my debugging.

I was able to get remote CLI debugging working in Eclipse, using xdebug, though I've not tried it with the zend debugger. I would assume this should work the same with ZSfE, if that's the "Zend Studio" you're using.

Since this is more along the lines of product support, your best bet is probably emailing the support people. We bought Zend Studio at my last job and they were always able to help us in a matter of hours.
Feel free to post the answer though, I am sure there are more people looking for it. :)

There's an option to debug a php script,
run->run as->php script
I believe it also has to be in your project root though. Just for clarification, Zend studio uses their own debugger, while the eclipse pdt project you have the option for Xdebug or Zend's debugger.

Haven't tried, but you can set the QUERY_STRING environment variable to the one that toggles the Zend debugger on.
Per this article.
export QUERY_STRING=start_debug=1&debug_host=<host name or IP of the local machine>&debug_port=<the port that is configured in your ZDE settings>&debug_stop=1
And then run the CLI script.

Remote command-line debugging is possible, I just tried it.
In my case I used Zend Studio + Zend Debugger.
This official article here by the Zend people will help you out, it's what I used. It explains all the parameters that must go into the shell command.
Make sure that you have the php.ini properly set on the remote server, and that it allows your IP address and it will work.
Also, you don't need to export the QUERY_STRING variable.
You can just do:
QUERY_STRING="start_debug=1&debug_host=[127.0.0.1]&no_remote=0&debug_port=10137&debug_stop=0" /path/to/php/binary /your/php/script.php
Running that on an SSH shell will light up your Zend Studio. Sweet!

Related

How to debug apis in PHP (without using var_dump();die();)

So I'm writing an api in php, and I'd like to use a full-service debugging tool. i.e., set breakpoints, view stack traces, inspect variables, etc. This kind of thing is very common in compiled languages.
I've checked out xdebug, and after configuring it to work with phpstorm (my IDE), I was disappointed to find that it only works when I run from within phpstorm, not when I actually service real api requests.
To add additional complexity to this, the api dbs are actually hosted on a vagrant instance, so although I write and edit code on my local machine, the code being run is in a virtual machine vagrant environment.
Any other way of doing this? Or should I just get used to something along the lines of print_r();exit; and rerun the request?
Use XDebug, and configure it properly. You can configure it to work without running the code from PhpStorm quite easily.
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.idekey = "vagrant"
Make sure those are set. Then, in PhpStorm, there is something that looks like a phone icon in the top right (along with the rest of the debugging and running stuff in the toolbar). Make sure that is all green (i.e. listening for connections).
You can use Xdebug to set breakpoints. It'll even work with CLI apps if you've set it up properly. You can even debug code from inside Vagrant VMs, or on remote servers.
You just need to do some research into how to set up your IDE. ;)
More details: http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
This may come in handy for you: https://www.jetbrains.com/phpstorm/marklets/
And this: https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html
And this: https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
Php xdebug
Take a look this example: http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
best tool available for php debugging is Xdebug. http://xdebug.org/ here is homepage.

Solution to debug PHP code on remote server, using remote IDE

There is an IIS server with the XDEBUG extension installed, running a PHP application. I can't change nothing on this server. Sometimes, the dev team here needs to debug it, without changing code. Just put some breakpoints and execute it step by step.
I can do it from my computer using Eclipse and remote debugging. But I would like to create a Debian server, in a VM, to make it easy for anyone with just a browser to place breakpoints and step debug that server, without needing to set up an environment.
I tried many Web-Based IDEs (codiad, cloud9, etc), but they don't offer XDEBUG integration. Is there any web-based IDE that I can install in my own server that offers PHP debugging? Please read this paragraph again and don't answer with spam
Or, is there anyway I could run something in the server side such as Sublime Editor, Notepad ++, or whatever, and see it running in a browser? Maybe a Java applet.
Any bright ideas will be very much appreciated! Thanks!
We just released support for debugging PHP with Xdebug inside Cloud9 IDE.
You can place breakpoints (normal or conditional), step over/in/out, set watch expressions, view the call stack, and inspect variables and values. There's also an REPL mode to evaluate code directly.
It's ready to try, but please make sure the correct dependencies are installed on the workspace by running the following commands:
$ npm install -g debug
$ sudo apt-get install php5-xdebug
Set your breakpoints, then click Run > Run With > PHP (cli) to start the debugger and PHP CLI script.
Would love to hear what your feedback is. Our goal is to add support for debugging PHP web pages and Python soon. The implementation is available open-source on GitHub (https://github.com/c9/c9.ide.run.debug.xdebug)
I also made a quick demo video to show you how it works.
I'm founder of Cloud9, so expect extreme bias.
If you are a decent (or better) coder, I have a solution for you. We already have an implementation of XDebug in javascript here: https://github.com/ajaxorg/lib-phpdebug. It might need a bit of updating as it was written for Node 0.6. It does support the latest xdebug.
In addition, we've just released an SDK that allows you to write plugins for Cloud9. Find more info here: http://cloud9-sdk.readme.io/v0.1/docs/getting-started-with-cloud9-plugins. It allows you to install Cloud9 on your own computer or server and you can develop plugins there. You can also distribute your plugin(s) via c9.io and use the SSH workspace feature to have Cloud9 automatically connect to your VM over SSH.
We just released the (pre-alpha) version of the SDK and are actively supporting the handful of developers on the mailinglist here: https://groups.google.com/forum/#!forum/cloud9-sdk.
Implementing a debugger for Cloud9 is actually fairly straightforward. Someone recently built a C++ debugger, which is still in PR here: https://github.com/c9/c9.ide.run.debug/pull/4. You only need to implement one class, the debugger implementation as documented here: https://docs.c9.io/api/#!/api/debugger.implementation. Since there's already an implementation of the xdebug protocol, tying these things together should only be a few days of work.
I hope this helps.

Step Through (Debug) PHP Code in Netbeans

I have an application I'm working on in which I make many AJAX calls to external PHP files. These PHP files get certain parameters, connect to the DB, and perform a task with them.
I just recently started using Netbeans for an IDE and love it thus far. However, whenever I put a breakpoint on one of my external PHP files (the ones I'm making AJAX requests to) and attempt to run the debugger, my breakpoints are never hit. Am I doing something wrong? Or does the Netbeans debugger not stop on the breakpoints of external files you are referencing?
NetBeans need to be configured to use xdebug, before you can strt debugging. For instructions on installing and configuring xdebug see here: http://wiki.netbeans.org/HowToConfigureXDebug
Here is a nice step-by-step tutorial for setting this up. A little less wordy than the netbeans documentation:
http://arturito.net/2011/05/21/local-and-remote-php-debuging-in-netbeans-with-xdebug-on-google-chrome-just-like-in-visual-studio/

Using ZendStudio with XAMPP

I had installed XAMPP, as a matter of convenience, since it installs php, apache (which is what I need) and, in addition, it installs other things like MySQL, but I'm not going to use now.
In XAMPP, I enabled the mssql module (editing the php.ini), to use the connection to Microsoft SQL, and everything works fine.
Now, I'm wanting to debug a script in PHP debugger with ZendStudio and I notice that there are two ways:
Internal
Server
[Internal], uses the ZendStudio "internal" PHP.
[Server], connect to a server (which is what I need).
The point is that I can not do it, I can not understand how it is configured.
I would like to use with the XAMPP apache and php.
I use Internal for now, but I get problems with the mssql module. I was looking at the Zend internal php, copied by hand the mssql dll and edited the php.ini (I am talking about the Zend) but still not working.
Any ideas?
You will need to install either Zend Debugger or xdebug on the server, and then configure Zend Studio accordingly. Both are fairly easy to install on XAMPP, and there are many articles available through Google that detail installation better than I can here.
If you choose to go with Zend Debugger, you shouldn't need to do anything else in Zend Studio, as it is the default debugger. If you opt for xdebug, you will need to edit your Studio configuration to use xdebug instead. This option can be found under PHP > Debug, and is a drop-down labeled PHP Debugger.
Now you can start a debugging or profiling session using the Zend Studio browser toolbar, or from the Remote Debug or Remote Profiling buttons in Studio. I highly suggest reading the Zend Studio manual for some more advanced debugging information.
Also, just to throw this out there, you can replace XAMPP with Zend Server Community, which has Zend Debugger installed and configured by default. Studio 7+ will pick up a Server installation and configures itself to use it automatically.
I'm not all that familiar with ZendStudio, but wouldn't you just use the "Server" option and point to http://localhost/ for the server to connect to?

Using Xdebug & Zend Debugger Simultaneously?

Is it possible to run both debuggers within the same PHP installation simultaneously. They both use different ports so communication with the client IDEs/other apps wouldn't be an issue.
I ask only because using the Zend Debugger with ZendStudio has proven to be much easier (fewer steps to start/stop debugging from the browser), but I really like some of the profiling tools available that only work with XDebug. So in a nutshell, I would love to be able to have the best of both worlds if possible.
http://www.suspekt.org/2008/08/04/xdebug-203-stealth-patch/ (in particular the last comment) seems to indicate that the profiling parts of Xedebug will work fine alongside Zend Debugger, with the patch installed.
It is possible - the simplest way on a development web server would be to run 2 different apache processes with different php.ini files referencing the different debugger modules
So, XDebug is known not to work with many Zend tools (I know Zend Optimizer for certain, I don't know about Zend Debugger but I wouldn't be surprised if XDebug has a built-in check for that).
Since you're running the debugger and profiler on a dev machine, I don't see why you can't maintain two separate ini files. Otherwise, you'll have to compile a custom version of yourself that bypasses the checks.

Categories