2

I need a script to be run every minute by a cron job. The script needs to include 2 files including 1 wordpress file, "wp-blog-header.php", and 1 non-wordpress file, my custom functions.php:

require_once (__DIR__ . '/../../wp-blog-header.php');
require_once (__DIR__ . '/functions.php');

The problem is that "requiring_once" "wp-blog-header.php" makes the cron not to run. I know because if I take it off and only include my custom functions.php, the cron job works as it is supposed to.

require_once (__DIR__ . '/functions.php');

I need to include "wp-blog-header.php" because I need to use wordpress functions. Is it because "wp-blog-header.php" might be also including other files?

Any idea how can I include this wordpress file?

My cron comand is:

php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php

Please help ! Thank you!

karlosuccess
  • 843
  • 1
  • 9
  • 25
  • Do you have a PHP errors file that you can post the error it's reporting? – HC_ Jul 08 '15 at 19:05
  • I am sorry for my ignorance but where can I find that? Any location? – karlosuccess Jul 08 '15 at 19:21
  • Are you using xampp? to locally test or anything like that? `\xampp\apache\logs\error.log` – HC_ Jul 08 '15 at 19:23
  • 1
    You should be including `wp-load.php` not `wp-blog-header.php`. Also, WordPress has a built in scheduler. You should consider using that instead of loading WordPress externally. You can make sure it runs every minute by triggering `wp-cron.php` in an actual cronjob. – Mathew Tinsley Jul 08 '15 at 19:26
  • @HC_ I am testing directly on the website – karlosuccess Jul 08 '15 at 19:35
  • @mtinsley but using the the wp-cron.php file or the WordPress codex articles for wp_cron or wp_schedule_event need a user or someone to actually visit the site... right? – karlosuccess Jul 08 '15 at 19:37
  • @mtinsley you mean using the wordpress built in scheduler and the setting my cron command to `php -q /home/enkaizene/public_html/soporte/wp-cron.php` or something like that? – karlosuccess Jul 08 '15 at 19:39
  • @karlosdpm Correct, normally the scheduler only works if your site has regular visitors, but you can trigger it manually with a real cronjob. – Mathew Tinsley Jul 08 '15 at 20:04
  • @mtinsley Thank you for the suggestion. I will give it a try! Cheers – karlosuccess Jul 08 '15 at 20:17
  • @karlosdpm, did you ever fix this? I'm having the [same problem](https://wordpress.stackexchange.com/questions/215981/wordpress-outside-of-wordpress-not-executing). – Pamela Jan 29 '16 at 09:26
  • 1
    @Pamela First at all, I ended up finding out that I actually needed to include `require( dirname( __FILE__ ) . '/wp-load.php' );` instead of `require_once (__DIR__ . '/wp-blog-header.php');` to get all the wordpress functionality. Secondly, the solution, the only way I could make this work was to actually point the cron job to what I call a "bridge" file and then from this file doing a cURL call to my desired file (the one that includes the wp header) and it's been working nicely ever since. – karlosuccess Feb 03 '16 at 01:19

0 Answers0