Question

I would like to move all files that are older than 24 hours. Currently I'm just deleting them. When I'm in the shell folder and I try to run the script in terminal: php clean_fc_export.php i get the error:

require_once 'abstract.php';

class Clean_Fullcircle_Old_Export_Files extends Mage_Shell_Abstract
{
    public function fclean()
    {
        /** define the directory **/
        $dir = "var/report/";

        /** cycle through all files in the directory */
        foreach (glob($dir."*") as $file) {
            /** if file is 24 hours (86400 seconds) old then delete it */
            if (filemtime($file) < time() - 86400) {
                unlink($file);
            }
        }
    }

    // Shell script point of entry
    public function run()
    {
    }

    // Usage instructions
    public function usageHelp()
    {
        return <<<USAGE
Usage:  php -f scriptname.php -- [options]
  --argname <argvalue>       Argument description
  help                   This help
USAGE;
    }

    // Instantiate
    $shell = new Clean_Fullcircle_Old_Export_Files();

    // Initiate script
    $shell->run();
}

PHP Fatal error:  Uncaught Error: Call to undefined function simplexml_load_string() in /var/www/lib/Varien/Simplexml/Config.php:510
Stack trace:
#0 /var/www/lib/Varien/Simplexml/Config.php(498): Varien_Simplexml_Config->loadString('<?xml version="...', 'Mage_Core_Model...')
#1 /var/www/app/code/core/Mage/Core/Model/Config.php(274): Varien_Simplexml_Config->loadFile('/var/www/app/et...')
#2 /var/www/app/code/core/Mage/Core/Model/App.php(391): Mage_Core_Model_Config->loadBase()
#3 /var/www/app/code/core/Mage/Core/Model/App.php(275): Mage_Core_Model_App->_initBaseConfig()
#4 /var/www/app/Mage.php(616): Mage_Core_Model_App->init('admin', 'store', Array)
#5 /var/www/shell/abstract.php(86): Mage::app('admin', 'store')
#6 /var/www/shell/clean_fc_export.php(44): Mage_Shell_Abstract->__construct()
#7 {main}
  thrown in /var/www/lib/Varien/Simplexml/Config.php on line 510

I looked inside my phpinfo() file and it shows that i have Simplexml loaded and active.

phpinfo

I'm running vagrant and VM with a lamp stack. I made sure that extension=php_xmlrpc.dll was un-commented out in both /etc/php/7.0/fpm/php.ini and /etc/php/7.0/cli/php.ini

Was it helpful?

Solution

The .dll libraries is for the windows, you should use simplexml.so on Linux. If you run the script from the CLI you can use next command to check is there extension installed or not:

php -i

you should see many configurations, and can found something like this:

SimpleXML

Simplexml support => enabled

Revision => $Id: b8b5c37931a53e50a937c0aef2a26d351e173215 $

Schema support => enabled

or just type:

php -i | grep "Simplexml"

return should look like this:

Simplexml support => enabled

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top