开发者

Keep alive solution for cron job

开发者 https://www.devze.com 2023-02-23 03:37 出处:网络
I have a hosted websolution and a script that update information backend for the site. My webhost allows cron and I have made a script that wget\'s to every hour.

I have a hosted websolution and a script that update information backend for the site.

My webhost allows cron and I have made a script that wget's to every hour.

The script checks the db-table with posts to update for the oldest updated post and update that. In the end of the script I use javascript refresh to do the same procedure again this time with the second oldest updated post and so on until all posts are run through. If I open the script in my browser it works fine but when my host sets up the cron the script does not continue after the javascrpt refresh.

How can I solve this with another refresh solution that will work until the my statement stops it just by letting cron start the script?

(I changed to this solution from one where all posts were updated in one pageload but since it started to time out I went with this)

script.php

$limit=3600;       

//Select the oldest updated po开发者_Go百科st

if($last_update<$update_to_limit){ //check if the post was updated during this run

        // Script that update the post and below the java refresh that repeats the script.

    ?>
        <script type="text/javascript">
                <!--
                window.location.href = "http://www.site.se/script.php"
                //-->
        </script>
    <?php
    }else{
        echo 'OK : All posts updated within the last : '.$limit.' s'; 
    }


Wget will not run Javascript, if you open your code from the browser, it will of course run it, that is the reason of the difference.

I don't really suggest the method you're trying to use. If you really want, you can call wget again from PHP, use cURL or I guess even header('Location..');. But it would be much nicer to solve this problem in one turn.

If your code times out, I'd recheck the way that PHP code is written, and try to find a better solution, that is not so time-consuming. Afterwards: is the DB good enough, are the indexes set, etc. Or, if you cannot optimize it (or you do not want to), you can use set_time_limit().

(One more thing: Java!=Javascript. If you want to shorten it, write js instead of java)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号