I'm developing a Flex application that make calls to PHP scripts. All work fine but sometimes and without any reason the app stops. It seems that something wrong in the call to the PHP script, bad response or simply there is no response and the app wait until such response.
My question is if anyone know how can I trace the response of a PHP script call within the browser. Is there any tool that can monitorize the call and response?
Thanks.
I would recommend using firephp with firebug both are FireFox Add-Ons.
Your PHP script would have to die and report what's broken. This report would go to the browser and you can do whatever you want with it.
Read up on the following functions:
http://php.net/manual/en/function.set-error-handler.php
http://php.net/manual/en/function.error-get-last.php
Or like Marc B said - XDebug will dump trace for you if have access to instalilng modules
Related
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.
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 have an Android application that is connectiont to a web server running MySQL DB. On the web server I have php files that run scripts and return JSON Objects to the client (application). I recently upgraded the versions of my web server and as of then, the SELECT statements are no longer returning anything to the client if they have parameteres, however if I run a SELECT with no parameters, it works fine. Has anyone ever encountered a similar problem?
To be more clear about my question:
Is there anyway I can debugphp scripts?
I thought maybe debugging via a web browser wouldn't work because the client is triggering the php files directly and not a direct access to the web.
All help is much appreciated!
Chrome has a set of tools that let you remote debug from your android.
Check them out: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
You could wirte your own error handler an let him wirting some debug informations to a own log-file. than you can read the log file and check it for errors
Look at the MySQL error log and the php error log on your server
Check you activated the correct php_mysql* extensions in the newly upgraded PHP
Run the scripts on the server through a browser with the same parameters that your app uses, watch for errors
Upgrade the PHP code running on the server so it captures any errors and does something OBVIOUS with them.
I would recommend to use XDEBUG for debugging PHP code, or any analogue for yours web server. It is really simple to set-up and use it with any PHP IDE (like Netbeans) and it gives you a lot of abilities to explore your application condition. There is no difference in what browser you will open link with ?XDEBUG_SESSION_START=netbeans-xdebug parameter.
Also you can watch MySQL and Web-server logs.
If you cannot do anything above and you need to watch network action (AJAX requests), you can set-up ADB and use chrome developer console for debugging js (or to see php var_dump() in ajax calls) in you android chrome browser.
If you need to debug js in native android browser - try to redirect to "about:debug" page, and after this you will be able to see browsers js console (in some cases this button appears only when console has something to show - error or any othe message, in some cases it just doesn't work).
Update Watch Duplicate Copy Move
As mentioned by others, you can debug using the error logs given by mysql and php. There are also IDEs which come with debugging tools for scripting languages like php.
With an IDE like phpStorm by JetBrains, which I highly recommend using over just a normal text editor, you can configure data sources like a connection to your MySQL db. This is useful because you can run scripts in the IDE and see whether it's the retreival of the data from your db or something in your scripts or handling of the JSON object back in the client. So if you configure a data source and run those same scripts and you get the correct data back then you know there is either something wrong in the code where you send the data or something wrong in the code where you receive it.
**p.s. I know that I am 5 years (oh my days its been 5 years since 2013) late to this post but none the less you never know who may be having this same issue and they stumble accross this answer
1st - Setup Xdebug for remote debugging with your IDE(Eclipse, PHPStrom, etc), and put breakpoints in your script.(for example here's link for setting up eclipse envirompment).
2-nd - When sending your url request to server add parametres to your url(http://your/url.php&XDEBUG_SESSION_START=ECLIPSE_DBGP&KEY=XXXXX,
-1st parameter - XDEBUG_SESSION_START=ECLIPSE_DBGP starts debugging session. (as for me I am using eclipse IDE for developing, so my key will be ECLIPSE_DBGP).
-2nd parameter - KEY=XXXXXX - is a session number(type any number here).
After that you'll get your code breaks at your debugging point in your script.
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'm debugging Ajax calls.
How do I know which specific PHP function is called by an ajax call ?
I can only see the request and the javascript code triggering the request, but I dunno how is handled on the request on server side ?
I'm currently inspecting all php code, but I was wondering if there is an easier way..
thanks
An Ajax call does not call a specific function, it merely executes a script. Look at the script, search for its "main" (Whatever name it has in your script) and you'll have the exectued function.
If you want a real debug environment and be able to set breakpoints in your php-code, refer to the zend debugger or xdebug. Both can be controlled with the pdt eclipse-plugin or other IDEs.
If you just want to see some small pieces of information, you can of course just add some echo's or var_dump's to your php-code and then use the firebug firefox extension to view the response to your ajax-requests, which contains the echoed strings.
I would recommend you make use of FireBug and FirePHP. FirePHP allows you to log from PHP to FireBug console. In this way you can log anything for example all the queries being run or log from methods/functions.
Just use firebug and after the request is sent, look for the response. e.g. function1 echo foo, function2 echo bar, if it's blank...none of those 2 function was called.
On my end, I'm using Safari and finding both request / response from an ajax call to a PHP script is a breeze.
Debugging using Firefox's addon FireBug, you can check out the request and response data content easily.
http://www.daniweb.com/web-development/php/code/216729
So by right, Ajax cannot access remote web server content, so you need the proxy page in the middle of the whole architecture flow.
So which means:
[Within Same Server]
PHP page using AJAX -> Web Services / Web Server that contains your response functions
[Within 2 Servers, Connecting to Remote Server]
PHP page using AJAX -> PHP Proxy Page -> Web Services / Web Server that contains your response functions
So the overall proxy page acting like a "middle-man" to connect to remote site.
[IMPORTANT]
Don't confuse router proxy and proxy page, but have the same theory but it is different thing.