Posts Tagged ‘PHP’

PHP Debugging on IntelliJ IDEA 10 with XDebug

The Overview

So after being told by my peers that print_r() was adequate, I embarked on a quest to get true PHP debugging working in a reputable IDE. Recently I’ve heard nothing but good things about IntelliJ IDEA 10, so I decided that would be my test subject. Don’t let the “J” fool you, while Java is its focus, this bad boy handles an array of languages and markups, including ActionScript, PHP, Groovy, Scala, Python/Jython, Ruby/JRuby, Clojure, Javascript, and HTML.

If you are a serious PHP developer and have not given debugging a fair chance, or a chance at all, you are killing yourself. So let’s do this thing from the ground up. WAMP, XDebug, IntelliJ, and magic. Follow these steps (for Windows) to reach my recent state of elightenment and PHP debugging bliss.

By the way, I almost gave up on IntelliJ entirely due to problems with debugging until Alex Petrescu () talked me down from the edge. I’m very grateful as IntelliJ is proving to be an excellent IDE.

Step By Step

  1. Download and install WAMP (I installed to C:\wamp)
  2. After installing WAMP, create a file named C:\wamp\www\info.php that contains the following code:
     phpinfo(); ?>
  3. Open the http://localhost/info.php in a browser to get your PHP configuration.
  4. Now view the source of the page in your browser. Copy the entire contents of the source to your clipboard.
  5. Goto the XDebug Tailored Installation Instructions and paste your PHP configuration source into the text box then click “analyse my phpinfo() output”.
  6. Follow the resulting instructions for adding XDebug to your PHP installation. Once you make those changes, make sure the new section of your php.ini looks like this (as per a C:\wamp installation):
  7. Download and install IntelliJ IDEA 10 Ultimate Edition (trial). It may not be necessary, but I included all the available extensions.
  8. Setup a basic PHP project in IntelliJ IDEA 10
    1. Goto File -> New Project…
    2. Select Create project from scratch and click Next
    3. Enter a name for your project and select Project Module under the Select Type heading and click Next
    4. Select “do not create source directory” and click Next
    5. Click Finish then OK when asked about starting a project without a JDK assigned.
  9. Create a PHP file to test debugging
    1. In the project panel on the left side, right click the project name and goto New -> PHP File
    2. Enter a name for your PHP file and click OK
    3. In the code panel on the right, enter the following and save the file:
      $a = 0;
  10. Click the vertical bar between the project panel and the code panel next to the following line to create a red breakpoint:
    $a = 0;
  11. Copy the PHP file you created in step #9 to your WAMP www directory (C:\wamp\www)
  12. Right click on the PHP file name in the project panel, then goto Debug -> filename.php on server
  13. In the resulting window, click the dotted button next to the Server dropdown
  14. Setup your deployment settings
    1. Select Local from the access type dropdown
    2. Click the Mappings tab and under “web path on server” enter a single slash “/” to specify the WAMP root. Click OK and then OK again to finish the configuration.
  15. Right click on your PHP file in the project panel again and goto “Run on server” or “Debug on server“. I’ve had inconsistent behavior using it, so try both if one doesn’t work.
  16. If all went according to plan, a browser should open and execution should stop at your breakpoint. If you look at your debug panel on the bottom on IntelliJ you should now see your PHP globals laid out. Congrats, you made it!

The Summary

I know, its not exactly a walk in the park, but its well worth the work to not have to pollute your code with copious print_r() calls. You can now have full access over your PHP as you would with any other enterprise level language and debugger. I didn’t go into any specific detail here, but I plan in the future to discuss all the ins and outs of PHP debugging in IntelliJ IDEA 10. Its looks to be a great IDE thus far.

If you have any questions, which is likely since I ran into some inconsistent behavior, feel free to comment and I’ll try to answer back as quickly as possible. Hopefully you’ll never even need to ask.

Happy PHP debugging!

Johnny Cash in Flash

Hi, I'm Johnny Cash

Click here or the image above for the demo.
→ View the source code.
→ Download Source:
NOTE: You’ll need to download away3dlite, , and to compile the code.

Inspired by the legendary Johnny Cash I decided to dive into a few AS3 development topics I haven’t gotten to yet to create a 3d equalizer and tribute to the Man in Black. Those topics, along with some other more familiar ones, include:

  • Playing audio in Flash with Sound and SoundChannel
  • Using the SoundMixer to generate values based on the audio
  • Searching for images with the Google API via
  • Creating a PHP proxy for beating Flash cross-domain security issues
  • Using Away3dLite for speedy 3d visualization (I even get 15 FPS on my phone!)
  • Using Prefab to export 3d models as native AS3 code for Away3d or Away3dLite.

This demo has a good bit more code than I usually post up.  It also uses a couple external libraries, namely away3dlite (3d rendering), (Google API), and (super useful AS3 utilities).  Rather than overwhelm you with mountains of tutorial-like rambling, instead I’ll leave this demo here to be enjoyed, make the source code available, and break down each of these topics into smaller tutorials/guides in the near future.

Sometimes your muse doesn’t need to be even slightly related to your field of creativity.  In fact, that can often make for the most interesting inspiration.