• Home
  • About Me
  • Resume
  • Useful Links
  • Português
  • Contact

EmanuelCosta.com

E-Commerce, SEO/SEM/Online Marketing, Web Development, Usability, WordPress & WooCommerce

  • LinkedIn
  • Twitter
Home » Schedule Tasks

PHPStorm, WordPress and Debug

Posted on November 18, 2015 Written by EmanWeb

Yesterday I had a bug to fix that once I did, realized I should give PHPStorm its credits. Here’s the scenario:

  • I wrote a plugin that runs a query every hour to get GravityForms leads, convert to CSV file and post to remote FTP server;
  • There was no error message or any indication that there was a problem in the code (see pic 1), even with WP_DEBUG set to true, when manually running the scheduled task.
pic 1
pic 1
  • The only information I had was that the query did have records that were not outputting to the CSV file.

Debug WordPress Cron Tasks

So, how to debug if there’s no error message? Well, here are the steps:

    1. Make sure to disable all the scheduled tasks. On your wp-config.php file add:
      //This will allow to run the task you want to debug individually. 
      define('DISABLE_WP_CRON',true);
    2. I use this great plugin to see the WP Cron events, it allows you create your own schedules and run them individually (as in the pic 1), named WP CONTROL 
    3. Then, using WP Control, edit the event you want to debug and set to a time in the past (pic 2).

      11-18-2015 3-08-27 PM
      PIC 2 – Edit Cron Event Using WP Control
    4. Now, with WP_DEBUG set to true, go to this URL: http://yoursite/wp-cron.php?doing_wp_cron
      You then can see the error message. Like the one below:

      11-18-2015 1-19-43 PM
      PIC 3
    5. Now, how to find the problem in the code? Well, the orange line in the pic 3 above shows exactly where the problem is.

Solving the Problem With PHPStorm

PHPStorm is a poweful IDE for writing PHP code. I was introduced to it early this year at WordCamp Orange County’s presentation from Joe Chellman  on debug WordPress for real. (I tried to find the video but seem not available).  Here’s his presentation slides: http://www.shooflydesign.org/files/wcoc-2015/#/

So, after I setup PHPStorm to debug my web application (I plan on posting about this sometime soon), set some breakpoints in my code, here are some screenshots that make me think PHPStorm is worth every penny (It costs under $100/personal license).

11-18-2015 1-15-43 PM
Note the inline debug information in the code and the bottom 3 panels with variables and specially the one on the right, where I “watch” a variable.

 

PHPStorm also allows you get information right in the code panel. See example below:

11-18-2015 1-21-00 PM

And there’s more 🙂 You can setup dynamic breakpoints so they will only fire if the condition is met:

11-18-2015 1-22-35 PM

This new method to debug have saved me tons of time fixing issues like this one. But not only that, it allows you also step line by line on others peoples code and see what’s going on under the hood. If you develop in PHP, I strong recommend taking a look at PHPStorm.

Do you use other IDE? Are you already using PHPStorm? Did you have a hard time setting up WordPress Xdebug on your development enviromment? Let me know your comments and experiences.

  • delicious Bookmark on Delicious
  • digg Digg this post
  • facebook Recommend on Facebook
  • linkedin Share on Linkedin
  • reddit share via Reddit
  • stumble Share with Stumblers
  • twitter Tweet about it
  • rss Subscribe to the comments on this post
  • print Print for later
  • email Tell a friend

Filed Under: PHP, WordPress Tagged With: Debug, PHP, PHPStorm, Schedule Tasks, WP-Cron

Find Here

About me

Hello, my name is Emanuel Costa. I build professional websites and help companies grow online. I write this blog to help myself about what I learned and perhaps help other people. I help organize meetups and whenever I can I attend tech events, specially WordCamps. Read more about me. (p.s.: Agora escrevo um blog em Português aqui: emanweb.com.br

Latest WordCamp:

WordCamps I Attended:

I am volunteering at WordCamp Las Vegas 2019″ title=

WordCamp Fortaleza

I'm attending WordCamp San Diego

I am Attending WordCamp Miami 2016


WordCamp US

Categories

  • ActionScript
  • Blogs
  • ColdFusion
  • CSS
  • Experience
  • Flex and Flash
  • Gadgets
  • Google
  • JavaScript
  • Linux
  • MySQL
  • PHP
  • SEO
  • SEO and Internet Marketing
  • SQL Server and T-SQL
  • Uncategorized
  • video
  • Web Development
  • WooCommerce
  • wordcamp
  • WordPress
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Dec    

Recent Comments

  • Peter Crouch on How to output a list of IDs in a field as recordsets / Como retornar uma lista de IDs como recordset
  • Simon on cPanel on AWS EC2 using Amazon Linux w/ Yours Nameservers
  • WordPress Developer? Really? - EmanuelCosta.com on Gracie Brazilian Jiu Jitsu and WordPress. What these two have in common?

Follow Me

  • Linkedin
  • Meetup
  • RSS feed
  • @emanweb

Navigation

  • Home
  • About Me
  • Resume
  • Useful Links
  • Português
  • Contact

Need quick tech advice? Pick my brain:

Copyright © 2025 · Focus Pro Theme on Genesis Framework · WordPress · Log in

 

Loading Comments...