Initialize WordPress environment in a script to be run by a cron job

℡╲_俬逩灬. 提交于 2021-02-10 20:36:27

问题


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' );

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?

Thank you


回答1:


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

wget -O /dev/null http://www.example.com/cron-test.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.



来源:https://stackoverflow.com/questions/31304811/initialize-wordpress-environment-in-a-script-to-be-run-by-a-cron-job

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!