0

I have one cron file that is called by the server once a day. In that cron file I do require_once() to another file with functions. In that file I have a echo just to let me know it's being called.

Now, the echo is called but not a function inside that 2nd file.

cron.php

error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors", 1);

//  external Calendar Sync
$the_file=AC_INLCUDES_ROOT."/ajax/syncExternalCalendar.php";
if(!file_exists($the_file)) die("<b>".$the_file."</b> not found");
else{
    require_once($the_file);
}
// other code
cronSyncExternalCalendar(); // this is ignored? or nothing happens

syncExternalCalendar.php

echo 'syncExternalCalendar.php loaded'; echo '<br />'; // this echoes
function cronSyncExternalCalendar(){
    echo 'Fired cronSyncExternalCalendar<br />';       // this doesn't(!)
}

The external file runs great if I call that function after declaring it (in the same file) and of course commenting it in the cron.php. But I cannot make it run from the cron.php.

Any ideas?

2
  • I just tested the exact same code, only removing AC_INLCUDES_ROOT, and it executed just fine Commented Mar 26, 2014 at 22:07
  • hmmm, can't see any reason that wouldn't work. If the function didn't exist PHP would complain, so if there're no errors it must be calling the function. You say this works when you call the function from syncExternalCalendar.php? Commented Mar 26, 2014 at 22:13

1 Answer 1

1

You have only defined the function. If you want it to run, you need to invoke it.

echo 'syncExternalCalendar.php loaded'; echo '<br />'; // this echoes

function cronSyncExternalCalendar(){
    echo 'Fired cronSyncExternalCalendar<br />';       // this doesn't(!)
}

cronSyncExternalCalendar();
Sign up to request clarification or add additional context in comments.

4 Comments

Patrick, I do that. As I wrote in the end that works great when I call it in the same file. Like you posted. But I want to call it from the cron.php file. And that doesn't work.
What are you using AC_INLCUDES_ROOT for?
It's to resolve the path of the file. But that sould be no problem since I get the echo from inside the required file.
Patrik! My bad! In the code between the require and the function calling I had a if statement with a die(). That was "killing it". Thank you for checking this and spending time helping!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.