WordPress.org

Forums

Set Cron Job in my plugins (4 posts)

  1. jhaba
    Member
    Posted 2 years ago #

    Hi ,

    I want to set a cron job in my plugins , the url for which i want to set cron job is ttp://localhost/wordpress/wp-admin/admin.php?page=get_data , what code i should write so that it can run automatically after 30 minutes without visiting this page.

    Thanks

  2. s_ha_dum
    Member
    Posted 2 years ago #

    You can use wp_cron but it won't run until someone visits your page. To get it to run at 30 minute intervals you will need to do something at system level (for a *nix system, use cron), not at the level of WordPress.

    Also, if you want your online webserver to connect to your personal computer, you can't use 'localhost'. 'localhost' means 'this computer'. Whatever server is running the script will connect to itself.

  3. jhaba
    Member
    Posted 2 years ago #

    Hey thanks for reply,

    But what client want is that he can install this plugin in any site and will able to set cron job .

  4. s_ha_dum
    Member
    Posted 2 years ago #

    Like I said, you can use wp_cron but it will not trigger until somebody, anybody, loads the site. Otherwise you have to use a system cron job. That is just the way it is. WordPress, or any other PHP web application, doesn't run in the background all the time like a desktop applications (FireFox, Thunderbird) does. WordPress only runs with a page a loaded. Otherwise, it isn't running at all. It isn't 'sleeping'. It isn't waiting. It just isn't running at all. If it isn't running, it can't do anything. That is all there is to it.

    PHP and the HTTP protocol itself are stateless. You can't run a precise cron job given those conditions. You have to wait for someone to access the site, kickstart the system, and then WordPress can check to see if 'cron' jobs should be updated. You cannot have WordPress kickstart itself every 30 minutes. You have to use some other mechanism.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags