最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cron - Sending out scheduled emails

programmeradmin2浏览0评论

Will wordpress run cron if I have scheduled emails to send? Seems like if no visit (request) is made to the site, scheduled tasks won't run and therefore emails won't be sent eg. hourly.

According to current situation, if there is no visit to the site for few hours ( and than visit is made) than all scheduled emails will be sent at the same time

How can I prevent this, is there a plugin to add cron task?

Will wordpress run cron if I have scheduled emails to send? Seems like if no visit (request) is made to the site, scheduled tasks won't run and therefore emails won't be sent eg. hourly.

According to current situation, if there is no visit to the site for few hours ( and than visit is made) than all scheduled emails will be sent at the same time

How can I prevent this, is there a plugin to add cron task?

Share Improve this question edited Jul 25, 2012 at 10:49 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jul 24, 2012 at 0:57 Bojan SavicBojan Savic 1231 silver badge3 bronze badges 2
  • How do you "have scheduled emails to send?", This is not a native WP function. So you must already be using a plugin. – Jim Maguire Commented May 28, 2017 at 16:53
  • On IIS servers I can create an HTTP application cache that times out and can be reloaded recursively. This acts like a background daemon task on the web. I use this feature to create 'keep-alive' pinging functions in my ASP.NET web apps a s standard feature. And there are even better solutions using Hangfire in Java or .NET languages. Is something like this available for Wordpress or as a PHP library? – Robert Dickow Commented Jul 8, 2019 at 17:14
Add a comment  | 

2 Answers 2

Reset to default 10

You cannot rely on wp-cron for consistent results so you have to look to the server level. Most enterprise-level Wordpress installations need some sort of consistent automation. This is how I automate WordPress in this type of situation.

You will need to add a crontab to the server itself. If you're running Linux, you can use crontab -e to get to the edit screen.

Then add a simple curl command to hit your site on a regular basis:

0 * * * * curl http://yoursite/ >/dev/null 2>&1

This command will run once per hour. The bits at the end send the output to null and removes the email functionality every time the cron runs.

I use this on my sites to get around wp-cron's fickle 'scheduling'. If you're not positive about creating a crontab schedule, check out this handy tool for generating a crontab command. http://www.robertplank/cron/

If you're on a shared host, hopefully you have cPanel which if enabled, will give you a GUI to add a cron job. If for some reason you can't add a crontab, I would consider finding a host that gives you shell access and allows you the flexibility you need.

I've never used a cron hosting service, but you could check it out if your host won't let you add a crontab. http://www.easycron/ is an example of a cron host. (Again, I don't know the reliability of these services)

Hope this helps you!

Overall

The schedule functions and cron filters are not considered to be a real API in WordPress. This has several reasons, but the most important is, that such stuff must run server side on a lower level than a content management system/framework like WordPress is.

Explanation

WordPress runs on PHP, which (simply said) communicates between the server and the browser (along with other programming languages like javascript). Therefore it is meant to run on ever request (by a user - who opens the page inside her/his browser). And without this sort of interaction, you can't run anything.

That's it. :)

Solution?

As WordPress (what this Q/A site is about) can't deliver a solution that works without user interaction, I can't give you any other advice, than to check what your host allows you and if you don't get around, ask them for help.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论