在要由cron作业运行的脚本中初始化WordPress环境 [英] Initialize WordPress environment in a script to be run by a cron job

查看:44
本文介绍了在要由cron作业运行的脚本中初始化WordPress环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须运行一个我想由cron作业运行的自定义PHP脚本.在该脚本中,我需要wordpress函数将用户插入WordPress表.我的脚本在wordpress安装的根目录中.我的脚本开始于:

I have to run a custom PHP script which I want to run by a cron job. Within that script, I need wordpress functions to insert users into WordPress table. My script is on the root directory of the wordpress installation. My script is starting with:

require( dirname( __FILE__ ) . '/wp-load.php' );

如果我直接在浏览器中运行脚本,那么我的功能以及其他所有功能都不会出错.但是,当cron命中时,它显然不起作用.应该发生的一切都不会发生.

If I run the script directly in the browser then my functions and everything else works with no errors. But when the cron hits it apparently does not work. Nothing that is supposed to happen happens.

只要有帮助,我的命令行是:

Just for if it helps, my command line is:

php -q /home/enkaizene/public_html/soporte/cron-test.php

是脚本问题吗?还是命令?我的脚本应该如何开始?

Is the issue the script? or the command? How should my script start?

谢谢

推荐答案

您可以使用wget将cron运行到网址.

You could run the cron using wget to the web address.

wget -O /dev/null http://www.example.com/cron-test.php

您将受到php超时的限制,因此您需要确保脚本的运行时间不超过您设置的超时时间-或增加超时时间.

You will be limited by php timeout so you will need to make sure the script doesn't run longer than your set timeout - or increase the timeout.

这篇关于在要由cron作业运行的脚本中初始化WordPress环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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