Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  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,948
    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,948
    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

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,536
    Plugin Contributions
    127

    Default Re: Admin custom cron job

    Dave, as you work your way through these issues, perhaps you'd like to add a "troubleshooting" section to our documentation to make it easier for the next person?
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

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

    Default Re: Admin custom cron job

    BTW, the initial error I encountered, 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, went away on my MAMP development system when I added the file I missed in post #6.

    swguy, I will take a crack at a troubleshooting section for the documentation.

    Dave

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

    Default Re: Admin custom cron job

    Continuing cron job troubleshooting...are directory and file references in a cron script relative to the script location, or must absolute references be used, or should some other command be used to set the working directory? Assume unix server and php script initiated by cron. I am seeing cases where the script works great called from a browser but fails when executed by a cron job. It appears that the script can not find certain files used by the script. Is this another auto-loading issue?

  10. #10
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,915
    Plugin Contributions
    13

    Default Re: Admin custom cron job

    Quote Originally Posted by Dave224 View Post
    Continuing cron job troubleshooting...are directory and file references in a cron script relative to the script location, or must absolute references be used, or should some other command be used to set the working directory? Assume unix server and php script initiated by cron. I am seeing cases where the script works great called from a browser but fails when executed by a cron job. It appears that the script can not find certain files used by the script. Is this another auto-loading issue?
    dave,
    it sounds like all files needs to be explicit stated where they exist in your cron job.

    that said, if what you want to do executes fine in a browser, have you thought about using wget? i have some cronjobs set up like:

    Code:
    0 1 * * * wget --no-check-certificate --delete-after 'https://myzencartsite.com/dosomething_cool.php?token=onlyRunifThisTokenisIntheGet'
    might that get around some of the problems you are running into?

    https://www.gnu.org/software/wget/
    https://linuxize.com/post/wget-command-examples/

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 
Page 1 of 2 12 LastLast

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