1
votes

I have a script which drives something in Suite CRM which I can run easily from the command line by just typing php script.php.

However when I run it using the cron, it fails after the line

echo "Defined sugarEntry\n";

I have also tried hard coding the path in the require statements and also tried require_once.

I've also set the relevant include path in /etc/php.ini, and this is the php that is being used in the cron. Is there anything else I am missing?

   <?php
        //Don't forget to set the include path in /etc/php.ini
        echo "Start \n";

        set_include_path(get_include_path() . PATH_SEPARATOR . $full_path);

        echo "Include path set to " . get_include_path()."\n";
        //error_reporting(E_ERROR);

        if(!defined('sugarEntry'))
                define('sugarEntry', true);
        echo "Defined sugarEntry\n";

        require(  'include/entryPoint.php');
        echo "Entry point included\n";

        require(  'custom/modules/Accounts/controller.php');

        echo "Include file set\n";

        $controller = new AccountsController();

        echo "AccountsController initialised\n";

        //$controller->debug = true;

        //Loop through all the Accounts records that are a customer
        $controller->sync_all_crm_to_smb();

        echo "Finished\n";

    ?>
1

1 Answers

0
votes

Instead of configuring the necessary paths why don't you try with an easier way. You can do the following in your crontab:

*/1 * * * * cd <path_to_your_script> & php <script_name>.php

I'm using */1 * * * * just for the example.

<path_to_your_script> is the path to the directory where you successfully execute the script through the console.

If this still doesn't solve your problem try this in your php script:

 #!/usr/local/bin/php
 <?php
 .......