Rikard
Rikard

Reputation: 7805

running function from another php file

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?

Upvotes: 0

Views: 51

Answers (1)

Patrick Reck
Patrick Reck

Reputation: 11374

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

Upvotes: 1

Related Questions