Best way to periodically execute a PHP script?

前端 未结 5 1514
感情败类
感情败类 2020-12-01 11:21

I\'d probably figure out a way to do this if I had full access to the server, however the problem is it\'s just a hosting service which leaves me with nothing but FT

相关标签:
5条回答
  • 2020-12-01 11:45

    You can use an online cron service to essentially pretend like you have cron access.

    Create php file with contents you would like executed

    Free Cron Online Website

    Set up your free online cron to execute that file every x minutes.

    0 讨论(0)
  • 2020-12-01 11:45

    If your hosting provider doesn't give you anything but FTP access, and you don't want to schedule a periodic request from another machine, then there's nothing you can do. You'll have to get a better hosting account, preferably one that lets you use cron.

    0 讨论(0)
  • 2020-12-01 11:47

    You can do without cron using the following solution (PHP only): How to run PHP cron tasks without cron available

    0 讨论(0)
  • 2020-12-01 11:52

    Why don't you use

    crontab
    

    Take a look here:

    Cron wiki

    0 讨论(0)
  • 2020-12-01 11:55

    Not sure if this is the correct approach, but I used to just trigger a script when the first user visits the site, and then send a <meta http-equiv="refresh"... to the user for his browser to refresh the page. The original PHP script would still run on the server, but the user will not see it anymore.

    Basically, something like:

    if( check if the user is the first visitor today ) {
        set_time_limit(0);
        echo "<meta http-equiv='refresh' content='1;url=..." />"; // put your site baseurl in here
    
        ... run your scripts here
    }
    

    Just an idea. Might not work. Just try it out.

    0 讨论(0)
提交回复
热议问题