用crontab执行php [英] Executing php with crontab

查看:109
本文介绍了用crontab执行php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按计划运行php脚本.所以我认为crontab是个好主意.我正在使用的服务器位于我不太熟悉的Linux上.所以我遇到的问题是,我不知道如何从php使脚本可执行.我需要引用该脚本,或将其放入可以从命令行运行php的文件夹中.所以我不知道给我的crontab提供什么路径,例如:

I'm trying to run a php-script on a scheduled basis. So I'd thought crontab was a good idea. The server I'm using is on Linux which I'm not that familiar with. So the problem I'm having is, I don't know how make the script executable from php. I need to reference the script, or put it into a folder that can run php from the command line. So I don't know what path to give my crontab, for example:

5  * * * * var/www/some/path/script.php

我在

/usr/bin/php

但是我在那里找不到任何php文件,也许我没有安装?我的php5和apache安装在:

But I can't find any php file in there, maybe I don't have it installed? My php5 and apache installation is in:

/etc/php5

所以我的问题变成了,是否有在其他文件夹中使用crontab执行php-script的脚本,还是我只缺少usr/bin/php中的php可执行文件?

So my question becomes, is there anyway to execute a php-script with crontab in any other folder, or do I just lack the php executable in usr/bin/php?

推荐答案

从命令行输入开始:

whereis php

以运行cron作业的用户身份执行此操作.这将向您显示可执行文件的路径.然后,您可以在cron条目中使用该路径(如果尚未在PATH变量中使用该路径):

Do this as the user that the cron job will be run under. This will show you the path to your executable. You can then use that path (if it's not already in your PATH variable) in your cron entry:

5 * * * * /your/path/to/php /var/www/some/path/script.php

编辑:如果仅安装了Apache PHP模块,则可能需要安装php5-cli(Ubuntu程序包名称)程序包.这将为您提供可从命令行运行的二进制可执行文件.

you may need to install the php5-cli (Ubuntu package name) package if all you have is the Apache PHP module installed. This will give you the binary executable that you can run from a command line.

这篇关于用crontab执行php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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