PHP PDO Class Not Found - cron job

Discussion in 'ISPConfig 3 Priority Support' started by markp, Jul 26, 2016.

  1. markp

    markp New Member HowtoForge Supporter

    Good Day - I have a cron job that I'm trying to run and I keep getting PHP PDO Class not found. The script can be run manually when I ssh into the server as a jailed user.
    Error Message from cron.log
    Fatal error: Uncaught Error: Class 'PDO' not found in /private/database.php:6​
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Seems as if you use a different php binary in the cronjob and on the shell if PDO is missing in one of them.
     
  3. markp

    markp New Member HowtoForge Supporter

    Maybe - I ran php --ini in a cronjob and logged the output -

    Code:
    Configuration File (php.ini) Path: /etc/php/7.0/cli
    Loaded Configuration File:         /etc/php/7.0/cli/php.ini
    Scan for additional .ini files in: /etc/php/7.0/cli/conf.d
    Additional .ini files parsed:      /etc/php/7.0/cli/conf.d/10-mysqlnd.ini,
    /etc/php/7.0/cli/conf.d/10-opcache.ini,
    /etc/php/7.0/cli/conf.d/10-pdo.ini,
    /etc/php/7.0/cli/conf.d/15-xml.ini,
    /etc/php/7.0/cli/conf.d/20-apcu.ini,
    /etc/php/7.0/cli/conf.d/20-calendar.ini,
    /etc/php/7.0/cli/conf.d/20-ctype.ini,
    /etc/php/7.0/cli/conf.d/20-curl.ini,
    /etc/php/7.0/cli/conf.d/20-dom.ini,
    /etc/php/7.0/cli/conf.d/20-exif.ini,
    /etc/php/7.0/cli/conf.d/20-fileinfo.ini,
    /etc/php/7.0/cli/conf.d/20-ftp.ini,
    /etc/php/7.0/cli/conf.d/20-gd.ini,
    /etc/php/7.0/cli/conf.d/20-gettext.ini,
    /etc/php/7.0/cli/conf.d/20-iconv.ini,
    /etc/php/7.0/cli/conf.d/20-imagick.ini,
    /etc/php/7.0/cli/conf.d/20-imap.ini,
    /etc/php/7.0/cli/conf.d/20-intl.ini,
    /etc/php/7.0/cli/conf.d/20-json.ini,
    /etc/php/7.0/cli/conf.d/20-ldap.ini,
    /etc/php/7.0/cli/conf.d/20-mbstring.ini,
    /etc/php/7.0/cli/conf.d/20-mcrypt.ini,
    /etc/php/7.0/cli/conf.d/20-memcache.ini,
    /etc/php/7.0/cli/conf.d/20-mysqli.ini,
    /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini,
    /etc/php/7.0/cli/conf.d/20-pdo_sqlite.ini,
    /etc/php/7.0/cli/conf.d/20-phar.ini,
    /etc/php/7.0/cli/conf.d/20-posix.ini,
    /etc/php/7.0/cli/conf.d/20-pspell.ini,
    /etc/php/7.0/cli/conf.d/20-readline.ini,
    /etc/php/7.0/cli/conf.d/20-recode.ini,
    /etc/php/7.0/cli/conf.d/20-shmop.ini,
    /etc/php/7.0/cli/conf.d/20-simplexml.ini,
    /etc/php/7.0/cli/conf.d/20-soap.ini,
    /etc/php/7.0/cli/conf.d/20-sockets.ini,
    /etc/php/7.0/cli/conf.d/20-sqlite3.ini,
    /etc/php/7.0/cli/conf.d/20-sysvmsg.ini,
    /etc/php/7.0/cli/conf.d/20-sysvsem.ini,
    /etc/php/7.0/cli/conf.d/20-sysvshm.ini,
    /etc/php/7.0/cli/conf.d/20-tidy.ini,
    /etc/php/7.0/cli/conf.d/20-tokenizer.ini,
    /etc/php/7.0/cli/conf.d/20-wddx.ini,
    /etc/php/7.0/cli/conf.d/20-xmlreader.ini,
    /etc/php/7.0/cli/conf.d/20-xmlrpc.ini,
    /etc/php/7.0/cli/conf.d/20-xmlwriter.ini,
    /etc/php/7.0/cli/conf.d/20-xsl.ini,
    /etc/php/7.0/cli/conf.d/20-zip.ini
    mysql-pdo is clearly there.

    here is the code creating the connection -
    Code:
    function get_connection($conn) {
            try{
            $dbh = new \PDO(
                            "mysql:host=" . $conn['host'] . ";dbname=" . $conn['database'],
                            $conn['username'],
                            $conn['password'],
                            array(
                                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                            )
            );
            } catch(PDOException $ex) {
                    die(json_encode(array('outcome' => false, 'message' => "Unable to connect.\n" . $ex->getMessage() . "\n" )));
            }
            return $dbh;
    }
    
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    That's the loaded ini files, it does no necessarily mean that the module gets loaded successfully, especially when using jails. You can use the class_exists() function in PHP to check if a class really exists and you might want to check the output of the phpinfo() command and compare that output from cronjob with the one from running at the shell directly.
     
  5. markp

    markp New Member HowtoForge Supporter

    Still working through this. Now it is not sending an email with the results of the script
    I have disabled this part of the script to see if it will work with out it.
    Mark
     

Share This Page