Disclaimer: May be a insane question but I have suffered a lot so came here.
I am working on a legacy application which uses JS + PHP + Web services (Written in spring).
Flow of the application :
Whenever any web service is called from JS it is redirected to one php file. The php file authenticates the user(using one web service) and then forwards the request to actual web service.
How can I debug this application ? I have debugged JS using Firebug and servr side code using Eclipse but never debugged such a application.
~Ajinkya.
I think there are a variety of things that need to be done, and I must say this question is sufficiently general as to not have a straight answer so I will do my best. As xdazz mentioned, var_dump (and die) are necessary from the PHP standpoint.
Whenever anything is returned to JS console.log it. In addition, ensure XHTTP requests are turned on for Firebug or alternatively view the output of each request in the Chrome Network tab.
With a combination of console.log, var_dump, and die, you can trace non-functioning parts of the application repeatedly step by step until you come across the bug.
Alternatively, and in the long run you ought to be doing this anyway, build error handling code into all the PHP code that is only activated when a debug flag is set to true. This way you can get detailed error messages and then when you deploy, you can turn them off to avoid compromising security.
If you are needing to inspect the entire lifecycle of a Web service request in your scenario you will need to combine a several techniques. Considering the fact that the scope of your scenario spans from client to server you will need to decide with what you will persist the information you need to inspect.
Personally, I would choose the path of least resistance which in my case would probably be cookies. With that being said you should be able chronologically log the necessary information via JavaScript and PHP, both before, during and after the request and even redirect has occurred.
This strategy would then allow for the information logged with cookies to then be dumped or analyzed via JavaScript, WebKit inspector or Firebug. Again, this is probably how I would handle such a scenario. Lastly, you can apply different storage strategies to this technique such as using a session or database for persistence.
Note: You can use something like WebKit Inspector, and possibly Firebug, to analyze data transmitted and received for GET, POST and even WebSocket requests.
Related
We are exploring the use of a PHP framework, Slim, and are interested in the ability to log, debug, and analyze all sever-side HTTP requests that framework views are making. We would like to see the results of those requests client-side.
For example. We have a route /foo. The view for route /foo makes three API calls to an API on the server, interprets those results, and returns a response. We would like to see the request parameters, header information, and response from those three server-side HTTP requests from the comfort of our browser. We've seen client-side debugging tools like the PHP Debug Bar, which looks like good scaffolding for displaying information from the server-side HTTP requests, but aren't clear how it would record and/or know of those server-side requests.
Previously, all of our API calls were made from the client and it was trivial to observe and debug these in browser development tools.
We've stumbled across standards such as HTTP Archive logs (HARs) that were made for capturing HTTP requests/response transactions in JSON form; is there way to record and bubble this up? More specifically, are there debugging tools in place for PHP frameworks that might have all this wrapped up in a tidy bow?
This would be for debugging only, as obviously it would make each route render much heavier for returning all that information around those server-side HTTP requests.
Any thoughts or suggestions would be most welcome!
I am working in a complex Webframework with lots of Javascript in the Frontend and lots of PHP in the backend. Since I’m new to it, finding out the workflow is quite a hassle. Is there a way to log the complete sequence of function calls (in PHP, JS or both) from the moment a request is sent until the response is executed (or the JS after the request has been sent is executed?) That would be really helpfull.
There's no perfect solution here but you will probably have to just use browser debugging tools like Firefox's Firebug or Chrome's debugger . Using these tools you can see JavaScript errors, AJAX requests, PHP (server) responses, individual page file loads etc etc.
All I can think of would be using Chrome developer tools, network tab in order to see the sequence of events. Or maybe even better, the HTTPFox plugin in firefox.
That will help you to find out the execution order of JS calls and which PHP files are accessed via AJAX.
What's happening on server side isn't easy to follow, but you could debug your code using XDebug.
I've a php file calling another php file which sometimes calls another php file to execute some actions (all through ajax).
What I use to do was to echo at different points to know upto where the codes are executing properly. But with this approach, I can keep echo-ing.
So how do I know upto where my code is executing?? Is there a tool for Google Chrome browser to detect it??
In your web browser, click the wrench icon, then "Tools", then "Developer tools". You can debug and step through JavaScript, you can see a timeline of requests with the request and response headers and bodies fully inspectable, etc. You should be able to debug all your AJAX request without any additional software/plugins.
Firebug plugin for Firefox allows you to put actual debug breakpoints and step through the code - much easier to debug javascript than echo'ing
If you look on how to set a debugging environent with PHP, you'll find a lot of dead ends, trust me, I did. Therefore you've got 2 choices.
A: Keep echo-ing which will leave a trail of painful echo's in your code.
B: Use a logger. I've used for a while FirePHP, which comes as a FireBug extension and lets you send debugging messages to the browser, which is ideal for debugging Javascript based apps with heavy Ajax.
Hope I can help!
The technique you're using is called bullet tracing. There's no real way to track which code executes and when within an php file (like breakpoints) but you can pinpoint points of errors on lines of code as provided by the php debugger.
When AJAX requests are made, you can track the progress through XMLHttpRequest States. To check the headers and payload of the packets being sent, you could use Firebug in Firefox 3.6.x, Firefox 4 Beta's built-in developer console, or Google Chrome's developer console. (Packet sniffers also work)
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
I'm trying to find a efficient way to watch the server log on a webpage, i don't mind building an app i just can't work out the best way to do it.
Is there a way to keep a stream open to a file with php and to the browser? or will it have to be done by polling the file every x seconds?
Thanks in advance,
Shadi
The best solution is definitely AJAX in some capacity. The only way to have the server "push" to you the way you describe (maintain an open stream) would require the HTTP connection to remain open which would ultimately trigger timeouts and consume a lot of resources. I would look into the Cometd library. The downside to this is that I believe it depends on Java although the site does mention perl, python and "other languages." In the worst case, you could use a specific jetty implementation just for log monitoring on a specific port. Regardless, that framework would most likely be your best bet.
Any web-based chat mechanism essentially uses a push architecture and would be good to look at for some inspiration. In this case, instead of users creating messages that are fired to other users, the server creates the events (when a log message is generated). Check out this article on Facebook chat for some insight into how they do it. Google chat might be worth looking into if you can find some stuff on the architecture.
For the actual logging, I'm not sure if you are in need of help for that, but log4php which is currently under incubation might be a good place to start as it provides you with a configuration that can simultaneously log to an arbitrary number of "loggers" like database, file, socket, etc. You could likely find one that would allow you to tie it into whatever push framework you elect to use.
Good luck!
Remember that the web model is essentially stateless (disconnected). Having that in mind when a client submits a request, the server processes the request and then send a response accordingly. You can have track of the clients action using cookies and/or sessions, but the resources reserved for a request are released after the response is submitted back.
I think that the best way to meet your goal, is to develop a web services that checks for the status of the log and fetch the diff (if any). Your app may consist of a web page with a div that will display the diff from the web service.
A script with a timer will trigger the call to the web service.
I will try to do something like this in a few weeks, and I will post the entire solution on moropo blog (spanish). You can ask for a post translation using the comments.
The best way to do it is to use AJAX to pull the file content every x seconds, giving the illusion of real time.
If you do want real time, you can use an XMPP server, but from what I can see, the first solution is far sufficient and does't require a lot of work.
Try wonlog.
https://www.npmjs.com/package/wonlog
You can stream multiple log files to a web browser.