Linux 用于运行 php 脚本的 Godaddy cron 作业设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7702885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Godaddy cron job setup for running php script
提问by Milos911
can you help me setup cron job on godaddy webhosting? I have php file that i need to run, it is located in cron subdirectory (so address is http://test.com/cron/file.php). What do i need to write in command input field, so this file is runned?
你能帮我在godaddy虚拟主机上设置cron作业吗?我有我需要运行的 php 文件,它位于 cron 子目录中(所以地址是http://test.com/cron/file.php)。我需要在命令输入字段中写什么才能运行这个文件?
采纳答案by aequalsb
NOTE:GoDaddy has been migrating all hosting packages over to cPanel. The itemized instructions below are for the older GoDaddy interface. The command is still the same.
注意:GoDaddy 已将所有托管包迁移到 cPanel。以下逐项说明适用于较旧的 GoDaddy 界面。命令还是一样。
At the time of this writing, on GoDaddy shared hosting, i could NOT use the following commands: ping, curl, nc, lynx
在撰写本文时,在 GoDaddy 共享主机上,我无法使用以下命令: ping, curl, nc, lynx
but i COULD use: wget
但我可以使用: wget
I successfully created a cron job using wget
to load a PHP file containing a call to mail()
.
我成功创建了一个 cron 作业,wget
用于加载包含对mail()
.
- log into your GoDaddy account
- click to expand the "Web Hosting" section and find the server in question
- click the "Manage" button (it used to be labeled "Launch")
- on the "Hosting Details" page in "Tools" section, click "Cron Job Manager" button
- on the "Cron Job Manager" page, click "Create Cron Job" button
- enter the title you want and select the frequency (1 hour is the most frequent allowed EDIT:GoDaddy has added 15-minute increments to the frequency choices.)
- enter the command below (with your info):
- 登录您的 GoDaddy 帐户
- 单击以展开“虚拟主机”部分并找到有问题的服务器
- 单击“管理”按钮(它曾经被标记为“启动”)
- 在“工具”部分的“托管详细信息”页面上,单击“Cron 作业管理器”按钮
- 在“Cron Job Manager”页面,点击“Create Cron Job”按钮
- 输入您想要的标题并选择频率(1 小时是允许的最频繁的编辑:GoDaddy 已为频率选择添加了 15 分钟的增量。)
- 输入以下命令(包含您的信息):
wget http://YOUR_DOMAIN/YOUR_PATH/YOUR_PHP_FILE.php > /dev/null 2>&1
wget http://YOUR_DOMAIN/YOUR_PATH/YOUR_PHP_FILE.php > /dev/null 2>&1
edit:as noted by Leandro, this is the method to make a cron job call a remote or local resource -- consult GoDaddy documentation if you want to call a resource locally only (which is also more secure if you're running more sensitive jobs)
编辑:正如 Leandro 所指出的,这是使 cron 作业调用远程或本地资源的方法——如果您只想在本地调用资源,请查阅 GoDaddy 文档(如果您正在运行更敏感的作业,这也更安全)
in "YOUR_PHP_FILE.php" code all the actions you want to be performed and include a call to mail()
(or whichever mail method you may want to use assuming you have configured that properly).
在“YOUR_PHP_FILE.php”代码中包含您想要执行的所有操作并包括调用mail()
(或假设您已正确配置,您可能想要使用的任何邮件方法)。
By using mail()
the SMTP relay server will already be set properly in the "php.ini" file to: relay-hosting.secureserver.net
-- which you can confirm using phpinfo()
.
通过使用mail()
SMTP 中继服务器已经在“php.ini”文件中正确设置为:relay-hosting.secureserver.net
- 您可以使用phpinfo()
.
回答by genesis
Use, for example CURL
or wget
or lynx
.
使用,例如CURL
或wget
或 lynx
。
lynx -s http://link.to/script.php
回答by James R
You can setup cron jobs through the Hosting Control Center. Check out GoDaddy's official page here: https://www.godaddy.com/help/create-cron-jobs-3548for a how-to on setting it up.
您可以通过托管控制中心设置 cron 作业。在此处查看 GoDaddy 的官方页面:https: //www.godaddy.com/help/create-cron-jobs-3548了解如何设置。
回答by shahana
Your cron job command should look something like the following (unless your directory structure is different of course):
您的 cron 作业命令应该类似于以下内容(当然,除非您的目录结构不同):
/web/cgi-bin/php5 "$HOME/html/sendy/scheduled.php" > /dev/null 2>&1
Regrads,
重新毕业,
shahana
沙哈纳
回答by Kamaro Lambert
If you are using Godaddy this should solve your issue.
如果您使用的是 Godaddy,这应该可以解决您的问题。
* * * * * /usr/local/bin/php /home/path/to/your/file.php > /dev/null
回答by user5835542
Cron Setup for GoDaddy Shared Hosting Accounts using Cpanel.
使用 Cpanel 为 GoDaddy 共享主机帐户设置 Cron。
*-->>Cron jobs run on GoDaddy's time zone in Arizona. Go Daddy doesn't publish this anywhere.
*-->>Cron 作业在亚利桑那州的 GoDaddy 时区运行。Go Daddy 不会在任何地方发布此内容。
Example: Run cron everyday at 1305 (1:05pm) pacific standard time.
示例:每天在太平洋标准时间 1305(下午 1:05)运行 cron。
5 14 * * * /usr/local/bin/php -q /home/username/public_html/scriptname.php
5 14 * * * /usr/local/bin/php -q /home/username/public_html/scriptname.php
回答by Sham Haramalkar
php_path -q file_name_with_absolute_path
/usr/bin/php -q /home/[user name]/public_html/test.php
1: How to know your php_path?
1:如何知道你的php_path?
echo exec('whereis php');
2: How to know absolute path of your file?
2:如何知道你的文件的绝对路径?
echo dirname(__FILE__);
回答by santosh devnath
In Godaddy Linux hosting. I used this command to run cron job.
在 Godaddy Linux 托管中。我使用此命令运行 cron 作业。
/usr/bin/php public_html/now your path
回答by Sapnandu
If you want to run a cron job in Godaddy. You can find following command, it will surely help you.
如果您想在 Godaddy 中运行 cron 作业。您可以找到以下命令,它肯定会对您有所帮助。
php -f /home/[user name]/[path to the file]