基本cron作业设置为每天执行php文件 [英] Basic cron job set up to execute php file daily

查看:120
本文介绍了基本cron作业设置为每天执行php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用cron工作的新手。我试图每天运行下面的脚本。 Go Daddy是我的托管服务提供商。我尝试使用Go Daddy的内置 Cron作业管理器来创建cron作业,但没有成功。我想知道是否有人可以帮助我开始创建一个命令,每天运行以下php脚本。

I am new to using cron jobs. I am trying to run the script below on a daily basis. Go Daddy is my hosting service provider. I tried using Go Daddy's built in Cron Job Manager to create a cron job, with no success. I was wondering if someone could help me get started on creating a command that would run the following php script on a daily basis.

有一种方法来设置单独修改.php文件?

Is there a way to set this up by modifying the .php file alone?

我很感激任何建议。

<?php 
            #!/usr/bin/php

            //Create mysql connect variable

            $conn = mysql_connect('host', 'user', 'pass');


            //kill connection if error occurs

            if(!$conn){

                die('Error: Unable to connect. <br/>' . mysql_error());

            }

            //connect to mysql database

            mysql_select_db("mdb", $conn);



            $results = mysql_query("SELECT * FROM files");



            $name_array = Array();



            while($row = mysql_fetch_array($results)){

                $name_array[] = $row['name'];

            }

            shuffle($name_array);

            for($i=0; $i < 2; $i++){

                echo $name_array[$i];

            }



        ?>


推荐答案

没有办法在文件中设置,它必须用cron来完成。如果您能够编辑/ etc / crontab,请添加以下行:

There's no way to set it up in the file, it must be done with cron. If you have the ability to edit /etc/crontab, add this line:

01 0 * * * root /usr/bin/php -f /path/to/page

否则,您必须按照说明< a href =http://support.godaddy.com/help/article/3547/creating-a-basic-cron-job?pc_split_value=2 =nofollow>此处,或联系GoDaddy了解为什么它不工作。

Otherwise, you'll have to follow the instructions here, or contact GoDaddy about why it's not working.

这篇关于基本cron作业设置为每天执行php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆