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

karlosuccess

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

user4287915

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Run Rails script in cron job?

From Dev

cron job to run under conda virtual environment

From Dev

cron job to run under conda virtual environment

From Dev

Run Cron Job on PHP Script, on localhost in Windows

From Dev

How to set a cron job to run a shell script?

From Dev

Cannot run cron job for a php script

From Dev

How to set a cron job to run a shell script?

From Dev

Cron job to run python script raises error

From Dev

Cannot run cron job for a php script

From Dev

Run a php script on localhost using cron job

From Dev

Cron job to check if PHP script is running, if not then run

From Dev

Cron job fails to run NodeJS script

From Dev

How to Run a JMeter Script as a Windows Cron Job

From Dev

How to run a wordpress cron job using a schedule hook?

From Dev

cron job in wordpress

From Dev

Concerned someone will run a php script only intended for a cron job

From Dev

Python script elicits error when run in cron job but at no other time

From Dev

PHP script does not run as cron job on Ubuntu Server

From Dev

Basic Cron job to run a shell script to append date in a log, not working

From Dev

Cron job to run python script at reboot does not work

From Dev

Cron job to run a php script for 24 hours then stop it

From Dev

Cron job does not run

From Dev

Not sure if cron job is run

From Dev

Cron job script not working

From Dev

shell script for cron job

From Dev

Cron job script not working

From Dev

Run a mySQL query as a cron job?

From Dev

CRON: Run job on particular hours

From Dev

Why does this cron job run?