How to step-through debug a PHP service in Eclipse? - php

I have a PHP service and calling page which I am attempting to debug in Eclipse (Xdebug).
Both are part of the same project.
I can easily set up the calling page for debug and step through the code.
When I get to the point where the calling page calls the service (POST) it goes forward without debugging and continues stepping through the calling page.
So, what I tried to do is set up to debug on the service page then browse to the calling page in a browser - ensuring that it posts to the service page using debug querystring - It does not debug the service but instead steps through the calling page.
Eclipse is new to me and I've worked mostly with Visual Studion / WCF with services. In that environment, I would start two instances of VS - one running the service, the other, the calling page. When the service was invoked, the debugger would automatically step through. I'm trying to achieve the same thing in Eclipse.
Again, the goal is to step through the service after it has had the proper test data posted to it (by any means).
Is there some other way to do this in Eclipse?
Thanks in advance.

Related

Why Symfony3 redirect slow

Recently I have tried to write a code in Symfony on page redirect (merely simple code for redirect without any other function), run it on localhost. However, the response returned is quite slow somehow (~500ms). What would be the possible cause of this as Laravel page redirect is faster than this.
When you open the Symfony profiler (just click on the debug toolbar that gets displayed in the bottom of the pages if you are in a development environment) there is a "Last 10" requests button you can click to view profiler information for last couple of requests.
Find your request that returned the redirect response, click on the Token value and you will be able to see in the "Performance" page what is causing the slowdown.
Also, when in development mode some of the changes that you make will require the container to be rebuilt and this can take a while in the development environment with xdebug enabled.

Connecting to SimPro API via Web

This is a very similar to the question posed at Use php and simPro API to list customers.
The response to that question suggests downloading examples from GitHub. I have downloaded the SimPro examples at GitHub and have them functioning on the commandline.
I want to be able to use a web page as an intermediary between my FileMaker Pro database and the SimPro API. I can pass data to a web page written in PHP. It can convert the data to JSON and form a call to SimPro receive a response and display the success or failure as a web page.
Presently I have my JSON data hardcoded so that I can test the process. When run from a web browser I don't get a result, though the code works perfectly well running from the command line.
I'm not sure what I need to do make the examples web compatible. Can someone push me in the right direction?
Would be more than happy to help - could you post a snippet of your code - minus the auth info of course - so that I can try to assist?
Do you have your code printing anything else to the browser first - so that you make sure the script is actually executing as it should from the web server side - and have you checked your web server logs for any errors?
In some cases I've seen this is usually due to PHP config (there are separate configs for CLI and CGI in most setups) and can mean whilst libraries are loaded in one environment they may not be available to the other. The web server also usually requires a reload if you have just loaded libraries for use within your script.
Hope that helps.

Debugging PHP - selecting a request for an Xdebug session

I work on PHP code with NetBeans and Xdebug. I use Xdebug for step-by-step debugging and the like.
I'm able to debug the flow of the default request, but not the flows generated by specific _get/_post or Ajax requests.
Anybody has an idea how can this be done?
When I run the debugger, a tab in my browser opened automatically with the following URL:
http://localhost/?XDEBUG_SESSION_START=netbeans-xdebug
Thanks.
Gidi
Ok,
it goes this way:
At the projects tab (top left of the screen in my configuration), right click on the name of the project, and then properties => run configuration
There you have to fill 3 forms:
1. project url - the base url of the project on web, typically http://localhost
2. index file - use the browse button and go to the local copy of index.php or whatever file serves this role for you. This form should contain the path to this file in the local filesystem , not on the web
3. arguments - any arguments you wish to path to your script through the URL
This should give you the ability to choose a custom URL for debugging
A possible problem: in this process you may loose the synchronization between web addresses and the corresponding files in your system. Google "path mapping in php debugger" if you encounter issues of this nature, and take the first result (which the system wouldn't allow me to link directly).
However this didn't work for me. I used server configuration to overcome this issue by redirecting URLs
Gidi
p.s.
All the above doesn't explain how to pass POST variables to your script while debugging (and I indeed don't know how to do it)
Perhaps you try to start a debug session as described above. As debug target you choose the nearest page to your POST request in the workflow. Then you interact with the web service, always having the debugger in netbeans running. With the interaction the debug session holds on, so you can fill forms etc. and send the POST request. Then switch to netbeans and debug as usual.
Perhaps you have to enable 'Break at first line' in the debug options, or set up a breakpoint in the php code, where the request is dispatched, in order to ensure the debugger halts while dispatching the POST request. Then you eventually will have to give the debugger a push at every page load.
Hope it helps

PHP code debugger on the fly

i have a website on my localhost, a quite complicated one with many links
is there a program that can debug for example, what happens when i click one link?or i login, etc
and show me each function called in each file and everything that's happening with the scripts?
You can use Eclipse + PDT or Netbeans with the PHP plugin and then install a recent version of xdebug. This will allow you to set breakpoints, inspect variables, etc.
If you want to get an overall view of your script/framework you can use the cachegrind files xdebug is able to produce and then use a viewer for those files (e.g. kcachegrind). This will help you understand how many times a function is called, what the most time consuming parts of your application are, etc..
when i click on test debugger it says A time-out occurred when the debug server attempted to connect to the following client hosts/IPs: 192.168.0.33 and 127.0.0.1

How to debug a web service written in PHP?

I've got a nice question here :)
I need to debug my web service written in PHP. Its client is written in C#.
After a couple of days of searching I realized this is not an easy task. At least it seems nobody knows the right solution.
What is the problem in, actually?
We have 2 popular PHP debugging libraries : PHP Debugger from NuSphere and XDebug extension.
The problem is they both are controlled from URL query string or with the help of cookies. For example, to enable debugging with PHP Debugger you need to add ?DBGSESSID=xxx parameter to your URL or to have DBGSESSID cookie.
But when your web service is called from the external client, the client doesn't have a cookie and doesn't add DBGSESSID url parameter. So how can we debug in this situation?
PS. I don't want to write to log files, see request and response headers/data or something like this. I want normal step-by-step debugging and breakpoints.
Anyone?
Well, I am answering to myself.
If we use PHPEd & DBG, then we can use the magic function DebugBreak().
Make sure PHPEd & PHP DBG Listenere are running, write
DebugBreak('1#127.0.0.1');
anywhere in your werbservice's code, make a call from the client, and voila! - you are in PHPEd on that line in debugging mode!
you could set xdebug.remote_autostart to 1 to always debug (no request parameter needed). this could be limited to some url with the <Location> or <Files> directive.
Or just log some debug information (using Zend_Log or Pear Log if you want a generic library) using var_export.
quick and dirty way is:
file_put_contents('/tmp/log1.txt',
var_export(array($_REQUEST, $something), true));
You could write data to a log file (meh).
Or output debugging information in response headers (if the client can view them). But as far as using breakpoints, you may be out of luck.
You could also look into connection hijacking on your local computer (something similar to the Firefox AddOn Tamper Data) where you can interrupt the request and add the url parameter.
Try SoapUI to issue requests manually and get the detailed responses. Not sure if you can fake the cookie, but you can control the endpoints, and therefore the URL to an extent.
I seem to remember that you can configure NuSphere's product to automatically attempt to connect to the debug listener with or without the DBGSESSID parameter (in query string or cookie). I'm not positive if that's the case, though. However, you can get the effect you're looking for by doing the following. It may be a little more manually intensive than you're hoping for.
Setup some sort of HTTP query/response listener.
Perform desired access against web service from client.
Manually re-issue those requests, appending the appropriate DBGSESSID
For a little more initial setup, but lower friction debugging later:
Configure your client to access an alternate URL.
Setup a proxy to listen on that URL (for debugging, I've seen Privoxy recommended, though I have no experience with it personally).
Configure the proxy to forward all requests to the real web service, appending an appropriate DBGSESSID parameter or including the cookie
I use the plugin Poster to help debug my php Webservice
Edit :
Found a better tool to debug web service : Advanced REST client Application
It's a Chrome Plugin, works great to test all kind of web services that use REST

Categories