We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39115
    • 15 Posts
    I'm trying to run some php script on cron. Unfortunately, the

    $modx->config['base_url']

    variable is not available. How to grab this value in cron job defined like:

    php -f /path/to/my/php/file.php

    ? does anyone know?

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      For one thing, base_url is the base of the web root, which has no meaning to the filesystem. Paths are for files, URLs are for webpage requests.

      A base_url might resolve to "/", while the base_path would be something like "/var/www/mydomain.com/public_html/".

      Most of the paths you need are to be found in the core/configs/config.inc.php file; the path to the site's core is found in the three config.core.php files. For example, mine have this:
      define('MODX_CORE_PATH', '/Applications/MAMP/htdocs/revo228/core/');
      


      See http://rtfm.modx.com/display/revolution20/Loading+MODx+Externally
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 13428 ☆ A M B ☆
        • 1,031 Posts
        Maybe with this: http://modx.com/extras/package/modxapilibrary

        And a PHP file like this:
        <?php
        $path = dirname(__FILE__).'/';
        
        define('MODX_SITE_BASE_URL', '/');
        define('MODX_SITE_URL', (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off' ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].MODX_SITE_BASE_URL);
        $modx_baseurl = MODX_SITE_BASE_URL;
        
        include_once($path.'modxapi.php'); //last release of Modx API file located in the root
        
        $modx = new MODxAPI();
        $modx->connect();
        $modx->getSettings();
        //$modx->startSession();
        
        // Set the base URL for any MODx snippets
        $modx->config['base_url'] = MODX_SITE_BASE_URL;
        
        //Run snippet
        $modx->runSnippet('snippetname'); 
        ?>