Table of contents:

Debugging

The following steps should allow you to figure out any issue with your AMFPHP application. Corrupt PHP installation, service errors, and client side Action Script errors are the three main areas that you should focus on when trying to debug an AMFPHP application. By narrowing your efforts systematically through each of these areas you will be able to quickly resolve issues and not waste time tracking something that is not broken.

Narrow it down!

If you follow these steps and are still confused use the mailing list and review the examples. If you are able to get to step three with a simple HelloWorld.php example I can assure you that AMFPHP is working properly. When you post to the mailing list or forum please let us know how far you got in this process before you ran into issues.

  1. With a web browser go to the remoting url:
    yoursite.com/amfphp/gateway.php
    Response should be:
    amfphp and this gateway are installed correctly. etc.....
    If this is not the case it is a Corrupt PHP installation.
  2. With a web browser go to the url of the service that is failing.
    yoursite.com/amfphp/services/HelloWorld.php
    If there is blank response the php interpreter was able to compile the class. If not it is a Service Error.
  3. Test the same service through the AMFPHP service browser. Pass the parameters to the method and you should get the expected result. If not look into the php class for why it is not handling your input as you have a Service Error.
  4. Use a proxie client so that you can see all the traffic between the Flash Player and the services. Make sure that the data in request is being sent as you anticipated and that the result set is being returned as anticipated. This assures that the inputs and outputs are correct!
  5. You are either not sending data properly or receiving the data properly but your issues is inside of Action Script. Review your code to make sure that your inputs and outputs are correct. This is a good time to hard code the input to the service call and trace all data that is returned from the service call.

Corrupt PHP installation

Your services and flash/flex will not work if the PHP installation is corrupt or missing modules. The PHP requirements for installation of AMFPHP are a minimal PHP install. However PHP installations and upgrades can be botched which inevitably stops your services. If PHP is not working properly you will most commonly receive a 500 error when it tries to connect to one of the services. This is because PHP had a premature end of script error.

Try the following steps to debug the installation:

  1. Check to make sure that you have a current version of php installed. As of AMFPHP version 2.0 there is no longer support for php 4.4.* ,PHP 4 was EOL 2007-12-31 , you will need to upgrade to PHP 5 for all future releases.
  2. Check your version and modules installed by uploading a php info page. A PHP info page is critical for debugging the php installation and also your services. When you browse to your php info page validate that it works. If it does php is running but may not be configured right. If it does not fix the php errors.
  3. The most common php installation error is improper permissions set on folders and directories that PHP uses. AMFPHP requires the ability to create a session variable and access the tmp directory! To debug this issue you will want to look at your php error logs.
  4. Use the HellowWorld example service to see if AMFPHP is really not working of if your services are not working. If you get a response you should start looking at your services.

Service Errors

First accept that your code could have bugs under certain conditions, old version get uploaded, and services can stop working when administrators upgrade php without all the previous modules. With this in mind it is critical to be able to isolate issues quickly.

  1. It is best to debug php classes with PHP tools. Stop playing with AMFPHP, the browser, your proxy tool and get connected to the server!
  2. Your working on PHP make sure you have error logging enabled. Add the ini_set values to the top of your class file if you do not have server wide logging.
  3. Run the class inside your services folder directly from a web browser. You should not receive any errors if the classes can be compiled by the php interpreter. If you do see errors resolve them!
  4. If you do not see any errors you are dealing with a runtime error. Open the class file add an instantiation of the object to the bottom of the file class inside the same file. Call the method that failed in AMFPHP with the exact parameters that you where trying to send the remoting method from the amfphp service browser or your flash application.

I highly recommend that you use some kind of IDE that allows you to debug your php code quickly. I enjoy using the Eclipse PDT Project because I can use one IDE for FLex, FLash, and php development. This toolkit has a debugger which makes the world a better place! Several people I know use NuSphere for there IDE and they love it.

In the end your service are just PHP classes. AMFPHP can not help you in writting better php code. PHP best practices such as unit testing and development environments will only increase your chance of success.

Action Script errors

If you are looking at Action Script I assume that you have made it through the first five four steps of Narrow it down and are still having issues. At this point we are sure our services work fine inside of AMFPHP. Action Script errors can be tricky to find. Little changes can create malformed data as inputs to the remote service. It is also easy to actually be recieving data from your service call but not handling it or displaying it. I always recomend having a dummy project handy for testing your services so that you are not lost in your own code. If you are using MVC it is easy to place trace statements in your inputs and responses in your service locator.

  1. Make sure that you have a NetStatusEvent handler and a SecurityErrorEvent handler defined for the service you are calling. If you are getting errors back you can find them in these handlers.
  2. Revert to a HelloWorld example. It is amazing how many people still use the wrong remoting URL or forget the www or https. Remember that your browser must be on the same URL as the NetConnection url or your service will not work.
  3. Hard code the input parameters that you used in testing your services into the service call. Also trace() in as at the service call what the inputs where that you were going to send. Are they the same? If this works you need to track back all your method calls and figure out why your inputs are corrupt.
  4. Trace a method in the responder method to make sure that it is even being called when you get data back. If it is not double check that you have the right method name specidied as the responder for your NetConnection.
  5. If the method is being called trace out all the data that is being returned. Somtimes your service may not have been implemented in the way that you thought you would get the data back. inumerate through the returned object until you find the right data. You may need to update your return value in your service to return the data in the expected format.

© amfphp.org | Disclaimer | Conditions of use