1

I have built a plugin that fires an Ajax call to connect to a third-party API. That API returns some Json, which I then save as a custom post with wp_insert_post.

Now, usually, this works. But, now and again, the save fails, with a "MySQL server has gone away" error. I'm assuming this is because the API took too long to respond (maybe 30 secs), and so the connection closed.

Does this sound like the correct conclusion? And if so, how can I handle this from within the plugin?

EDIT: 20 secs doesn't seem long enough for a timeout, so I'm baffled by this one...

0

2 Answers 2

0

You could try what wp-cron.php does and set in your AJAX handler:

ignore_user_abort(true);

But this might cause other problems, for example when the API takes an hour to respond. :)

Try to log all API response time for while to see if that is really the problem.

1
  • I tried this, but without success. I'm now wondering if it is timing out at all, after only 20 secs.
    – vancoder
    May 9, 2013 at 18:47
0

At risk of giving the obvious answer you probably already tried... assuming everything else is good to go, WordPress does cap execution time at 30 seconds (I think). 20 seconds could seem like 30 pretty easily yea?

The codex recommends adding php_value max_execution_time 60 to your .htaccess file and max_execution_time = 60 ; and you could also try adding set_time_limit(x) in your wp-config or on the script that fires the ajax in your plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.