First, you’ll have to determine an average time to execute your job. Run it once every minute, five times. Use error_log('Start');
, and error_log('End');
to mark the start time, and the end time. Take an average of all five results and round it up to full seconds. Prepare your job to execute its logic 6 times in a loop:
$avgExecTime = 3; //replace this with the average execution time from your tests
$sleepTime = 10 - $avgExecTime;
for($i = 0; $i = 5; $i++) {
//
// your logic goes here
//
if($i < 5)
sleep($sleepTime);
}
Now, you can set your system cron to run this job every minute, forever.
Note: make sure that your job’s average execution time is less than 10 seconds. If it is not, increase the frequency to 15 seconds, and modify your job accordingly.
Related Posts:
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- How ( and mostly at what time ) can i prevent the alternate cron from running?
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- Setup wp_schedule_event within a custom plugin
- WordPress cron job running more than once
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Cron: Update four post at Hour
- Activate Plugin Automatically After Set Time
- Better way to run heavy scripts using WordPress database
- WordPress Cron function is not working
- Adding custom cron_schedule prior to wp_schedule_event
- Schedule WordPress Auto-Updates to only run during business hours
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- How to remove duplicate sub-menu name for top level menu items in a plugin?
- category_name not working (not showing up in sql query debug)
- How can I make my custom shortcode work in a Custom HTML Widget?
- How to Loop Plugin Option Field Set?
- Update Multiple Post Meta for the Same Post In One call?
- Updating WooCommerce variable product stock issue
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- Rename existing old uploaded images containing accented French characters (not during upload)
- How to Create a Directory in a Plugin Folder?
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- Create plugin that works in background
- Checking for user role in a custom plugin
- HELP: Integrating WP with raw PHP code once published button is hit
- Loading class files via autoload method
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Getting media library popup in custom plugin admin page
- jQuery function didn’t work in my plugin
- Escape when echoed
- Why is wp-cron only executing on page visit?
- Write to / remove from default .htaccess file from plugin?
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- How would I go about creating a user ranked post popularity page?
- wp_schedule_single_event not working: cron job is triggered but nothing gets executed
- Redirect to another page using contact form 7? [closed]
- Create a plugin from within WordPress
- Class variables not correct on page
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- Activate my plugins via FTP
- How to set intervals in cron jobs?
- Why is my custom post type not being activated on plug-in activation?
- How to add apply_filter for a class property in plugin
- A server-side hook failed when committing plugin code to SVN
- Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection
- How do I add $_SESSION[”] to my wordpress page?
- output html on post or page from custom plugin [closed]
- How to Schedule Cronjobs for start of every month and year
- Built a second plugin but it overwrote the first one
- How to delete all categories programatically?
- How to use custom Javascript code inside a plugin?
- How to add/change (woocommerce) product tab icon
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- I want to generate the pdf and save it in library?
- Using meta_query in a WP_Query not working for numbers properly
- How to write to a separate PHP file in plugin settings
- Create “new pages” within the admin section of plugin
- More gentle way to hook WordPress custom url
- How to display results from a data table with an encrypted user id?
- What causes wp_schedule_single_event to fire off?
- How to Add text value in Automatically in this conditions?
- Checkbox show / hide output result
- WP Import All Multiple Dynamic Link Imports
- admin_notices show after load completed
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- Why is my shortcode not working?
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- implement checkbox or toggle switch in plugin code
- 500 Internal server error wp_handle_upload_prefilter
- Cron job shedules replace?
- Create a form and have custom menu display based on user answers?
- Can’t access 3rd party API, code works on local server but not on wordpress
- Get post content inside plugin class method
- WP_CRON issue with UTC and local time
- Problem with conditional woocommerce custom checkout field
- WordPress crob job performance
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- How can I insert a record into a custom table from my custom form in my custom admin page?
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Load my plugin before cache
- How to fix ‘Call to undefined function do_settings()’ error?
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- how to search through plugin in wordpress cimy-user-extra-fields?
- wp_handle_upload – specified file failed upload test
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week
- How to make a Template page to show the information of different things Shop and Product page?
- How to Save Category and Delete Category in same Function
- public custom posts not showing in my wordpress plugin