Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many requests to Open Exchange Rates #6

Closed
MosheBaram opened this issue Jun 26, 2015 · 18 comments
Closed

Many requests to Open Exchange Rates #6

MosheBaram opened this issue Jun 26, 2015 · 18 comments
Labels

Comments

@MosheBaram
Copy link

Since updating to version 1.4 I see the updates going from Open Exchange Rates hundreds of times daily instead of the configured setting of once per hour. Updating to 1.4.1 didn't seem to change anything with it. See my Open Exchange Rates account statistics attached here (23.06 is the date of update to 1.4, see the jump in the stats, 25.06 is the date of update to 1.4.1).
wp-currencies bug

@unfulvio
Copy link
Owner

This is a duplicate of #5
but I'm aware of the issue, I thought it was fixed in 1.4.1 but evidently not, I'm sorry for that - could you download and overwrite the plugin with the current one in the master branch? I think the issue is fixed now but I need more people to confirm that

thank you

@MosheBaram
Copy link
Author

Thank you for the quick response!

I have updated from master about 3 days ago, and the issue has been resolved. Unfortunately, now the plugin doesn't make any requests to Open Exchange Rates, so it does not work. I tried removing the plugin completely and reinstalling it from the latest version released (1.4.4), and it doesn't seem to work as well.

@unfulvio
Copy link
Owner

Urg. Would like to have some help on this - I guess this is why some people don't speak very highly of wp cron (which is not a real cron...).

In the first versions of WP Currencies I was not using wp cron but a rather rough check each time you fired any of WP Currencies functions. But that was heavy. Because it did a timestamp check between the timestamp saved in db and the current time. If more than the specified interval was passed, it would pull the data from open exchange rates, update the db and then proceed with the rest of the function. As you can see, it wasn't very efficient. So I thought of moving to wp cron and let wp cron manage the updates part as a separate process, but then these issues started popping out.

So, what we have now is an "update" method in Rates class:
https://github.com/nekojira/wp-currencies/blob/master/includes/rates.php#L64

This method is called by "update_currencies" method in Cron class:
https://github.com/nekojira/wp-currencies/blob/master/includes/cron.php#L41
It's wrapped with DOING_CRON check... but from your latest comment seems ignoring it, as DOING_CRON is never true - I might suggest you to read this troubleshooting just in case to rule out some exceptions: https://github.com/nekojira/wp-currencies/wiki/Troubleshooting

"update_currencies" is also the callback of 'wp_currencies_update' wp cron action:
https://github.com/nekojira/wp-currencies/blob/master/includes/cron.php#L29

'wp_currencies_update' is scheduled in 2 possible occurrences:

  1. upon plugin installation & activation, this method is called:
    https://github.com/nekojira/wp-currencies/blob/master/includes/cron.php#L56
    It's likely to do nothing since no default API key is set, but creates the wp cron job
  2. Then, when you update either the interval or insert/change an API key, this method in Settings class changes schedule if needed:
    https://github.com/nekojira/wp-currencies/blob/master/includes/settings.php#L211

This last method is only called when 'wp_currencies_settings' option is saved:
https://github.com/nekojira/wp-currencies/blob/master/includes/settings.php#L40

At the moment I'm a bit lost, will try to ask around why this is not working.

Do you mind checking the first link for troubleshooting? Maybe your cron is not working properly.

@unfulvio
Copy link
Owner

I've looked around
https://wordpress.org/support/topic/wp-cron-not-running-1

there's some possibility that object caching is interfering with DOING_CRON

first of all you should check if you have this in your wp-config.php:

 define( 'DISABLE_WP_CRON', true );

If you have it, delete it and try if now WP Currencies updates work.

Then, if you are using some caching plugin, you could try to disable them and see if the problem still occurs. You can use Crontrol plugin to inspect Cron jobs in your installation. To verify if updates work, change update frequency and hit save on WP Currencies options, that should trigger an update.

@unfulvio
Copy link
Owner

Ok luckily someone pointed out a possible solution which I implemented in last commit.

@StewieGm can you download the last version of the plugin from Github and try it?

@extrapixel
Copy link

Giving it a try right now. Updated via WP, set API-Key. No request as of yet (table not yet updated). Will report in some hours.

@MosheBaram
Copy link
Author

Updated about 12 hours ago, still no requests. I see the last commit has changed, updating again now.

@unfulvio
Copy link
Owner

try version 1.4.6 - tested locally appears to be working fine

every time you save changes for an api key and new schedule, it should trigger an update

however at the moment it doesn't do that if the values in the plugin options (api key, scheduled interval) are exactly the same - I might change this to force an update even when the values (api key, scheduled interval) are the same as the old ones

do a test with Crontrol to check if a schedule is set and if it changes when you change setting

when a schedule is set, it should run once first in any case, regardless of interval

@unfulvio
Copy link
Owner

the latest commit on master branch clears the scheduled event and sets a new one on 'save changes' regardless if settings are changed or not

@unfulvio
Copy link
Owner

on a last note, since 1.4.6 there is the PHP function wp_currencies_update normally you don't want to use this since it's the scheduled event callback, but if called directly it does force an update regardless of cron

@extrapixel
Copy link

I can confirm: no requests made at all with version 1.4.6

@extrapixel
Copy link

just tried the same with latest master. (deactivated, deleted, made sure no crons lef-over, no data in wp-currencies table). Then installed freshly, set api-key and freq to hourly. Result: no request, no cron-job installed in wp-cron.
After changing values a few times for the frequency, suddenly there was one request and the cron got installed. But definitely not after saving the settings for the first time.

At least it seems to do "sane" requests to the api now.

@unfulvio
Copy link
Owner

currently (as in master branch) it's working for me so I can't isolate the issue yet

maybe cron is not working properly on your installation?

have you tried running the function wp_currencies_update()? that should force an update no matter what

There is indeed a chance that a caching plugin or a particular host configuration might interfere with wp cron.

I think you should try following the steps in the troubleshooting section of the wiki:

https://github.com/nekojira/wp-currencies/wiki/Troubleshooting

mainly, trying to disable plugins - you can also try running WP Currencies in a local environment

@unfulvio
Copy link
Owner

ah one last thing after your last comment, you shouldn't rely on openexchangerates.org request counter to know if a request came from your WordPress installation - there's always a delay sometimes of several minutes and you can't tell from where the request came from (even if you are confident you only have 1 installation with that api key)

a more reliable way to tell is to check your wpdb with phpmyadmin or similar and check timestamps in the wp_currencies table

@extrapixel
Copy link

yeah i know. did check the timestamp in the table.

At the moment wp-currency isn't of much use for me anyway - because I need it to get rates into WooCommerce. And there's a bug in WCML (their filters don't fire). Will be fixed in WCML 3.7.

So I'm sorry I need to focus on my other projects for now. But I will report back as soon as I'm implementing the stuff with WCML.

Btw: heard back from openexchangerates regarding the over-quota issue. It doesn't fit here actually, but you might be interested in that anyways:

All the monthly usage quotas are 'soft limits'. In other words, if you exceed your usage allowance by a certain amount or more, we'll simply send an email notification, then two more over the month afterwards if the usage doesn't drop.
The thresholds for paying users are higher, and there's no extra charges or penalties for exceeding the limit (but we would get in touch and ask you to upgrade if the usage stays too high.)
After three notifications, if we don't hear from you or the volume stays over limit, access may be restricted temporarily or permanently. I’d recommend designing your integration carefully to ensure your account stays under the limit as much as possible.

@unfulvio
Copy link
Owner

to be entirely honest I had much head scratching when dealing with WPML plugins in the past. I plan to use Babble https://github.com/Automattic/babble for my future multilingual needs (it's backed by Automattic at least...).

If you need WPML only for WCML in my modest opinion it's really overkilling as it would add a huge load on your installation. I think you could achieve multi-currency support in WooCommerce alternatively.

As for Open Exchange Rates sounds fair enough with them - and WP Currencies fits that recommendation to design the integration to keep the requests under a limit - this too many requests issue was a regrettable accident.

Technically if WP Currencies grows one could add other providers like Yahoo or Google Finance. But being a free plugin there's a limited amount of time I can spend on it.

@extrapixel
Copy link

Yeah let's put it like it is: WPML is a bloated piece of crap. Dealing with their (obviously outsourced) support is just a pain.
Thanks for the hint regarding babble, I'll definitely check it out.

@unfulvio
Copy link
Owner

you're welcome, if you like this plugin you could star it or vote/review it on
https://wordpress.org/plugins/wp-currencies/
for any other thing just come back to this github repo or issue pull requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants