Results 1 to 10 of 14

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Admin custom cron job

    I have followed the directions given in the documentation here but am getting the following error message when executing my custom cron job:

    [04-Mar-2022 15:30:00 America/New_York] Request URI: cron, IP address: cron
    #1 mysqli_connect() called at [/path to site/includes/classes/db/mysql/query_factory.php:63]
    #2 queryFactory->connect() called at [/path to site/renamed_admin/includes/init_includes/init_database.php:18]
    #3 require(/path to site/renamed_admin/includes/init_includes/init_database.php) called at [/path to site/renamed_admin/includes/application_bootstrap.php:162]
    #4 require_once(/path to site/renamed_admin/includes/application_bootstrap.php) called at [/path to site/renamed_admin/includes/application_top.php:15]
    #5 require(/path to site/renamed_admin/includes/application_top.php) called at [/path to site/renamed_admin/my_custom_cron.php:55]
    --> PHP Warning: mysqli_connect(): (HY000/2002): No such file or directory in /path to site/includes/classes/db/mysql/query_factory.php on line 63.

    I assume it can't find the file where function mysqli_connect is and I'm not sure where it is. A search of my site failed to find it and I don't know where it is. I have uncommented the define for DB_SOCKET but no difference. The cron file is in the admin directory and the cron job is executing but failing at line 55 where the code is require(includes/application_top.php).

    What am I doing wrong?

    zc1.5.7c, PHP 8.0.8, mysql 5.7.34

  2. #2
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Admin custom cron job

    I found the solution to the problem above but have another problem. First the solution. I was running on my development system, MAMP Pro on a Mac. Looking in the admin tools menu under Server/Version Info, I found under the mysqli topic an entry for mysqli.default_socket. It is essentially a path to mysql.sock. Copying that entry and pasting it into the line in the my_custom_cron.php file that defines DB_SOCKET fixed the problem.
    Code:
    // Some servers' PHP configuration doesn't know where to find the mysql socket correctly (evidenced by getting errors about mysqli and mysql.sock, esp when running cron or command-line scripts, such as this one)
    // uncomment the following line ONLY if your server's configuration requires it and you don't already have this in your configure.php file
    define('DB_SOCKET', '/tmp/mysql.sock');
    Now the new problem. The function_exists(my_custom_function) is failing to find the called function. I have no clue why it can't find the function. It's located in admin/includes/functions/extra_functions/my_functions.php. I checked the function name in both places; it's the same. I followed the guidance given in the above-cited documentation and can see no difference between the model code for currency exchange rate and my code. The relevant code follows:
    Code:
    // main execution area
    if (function_exists('my_cron_function'))
    {
      if (IS_CLI == 'VERBOSE' && $is_browser) echo '<br><pre>' . "\n";
      if (IS_CLI == 'VERBOSE') echo 'Processing... ' . "\n";
      my_cron_function();
      if (IS_CLI == 'VERBOSE') echo 'Done.' . "\n\n";
      exit(0); // returns 0 status code, which means successful
    } else {
      echo "Error: Function not found: my_cron_function.\nMake sure you have placed the my_custom_cron.php file in your (renamed) Admin folder.\n\n";
      exit(1);
    }
    Any help or suggestions would be greatly appreciated.

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,942
    Plugin Contributions
    96

    Default Re: Admin custom cron job

    You could use /admin/currency_cron.php as an example.

  4. #4
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Admin custom cron job

    Thanks lat9 but I am using that code as a model. I've uncommented
    Code:
    define('STRICT_ERROR_REPORTING', TRUE); // commented out for normal use
    define('DEBUG_AUTOLOAD', TRUE);         // commented out for normal use
    with no information being reported. If I call the function when normal admin is running, my function works perfectly. It seems like /includes/functions/extra_functions is not being loaded when run from a cron job.

    Really weird.

    Dave

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,942
    Plugin Contributions
    96

    Default Re: Admin custom cron job

    Agreed on the weirdness. /admin/auto_loaders/currency_cron.core.php (assuming that you're re-using that loader-prefix) brings in the init_general_functions.php which, in turn, loads any/all .php files present in the admin's /functions/extra_functions sub-directory.

  6. #6
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Admin custom cron job

    Thank you for the clue lat9. It would really help if I read and followed ALL directions in the documentation, especially:
    Copy the file admin/includes/auto_loaders/currency_cron.core.php to admin/includes/auto_loaders/my-script_cron.core.php Change the inclusion of localization.php to your own functions file.
    .

    On to the next loading error within my function.

    Very embarrassed Dave

 

 

Similar Threads

  1. v151 Cron Job
    By Cenkki in forum General Questions
    Replies: 19
    Last Post: 8 Sep 2014, 02:54 PM
  2. Admin auto login for a cron job
    By Gigo in forum Customization from the Admin
    Replies: 20
    Last Post: 9 Aug 2012, 07:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg