The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

pdo library and crontab problem

Discussion in 'General Discussion' started by upsforum, Jul 12, 2011.

  1. upsforum

    upsforum Well-Known Member

    Joined:
    Jul 27, 2005
    Messages:
    446
    Likes Received:
    0
    Trophy Points:
    16
    I have a vps with suPHP, suhosin and PDO library installed, I need of run a php script in crontab with # php cli modality. It work from webserver (http) and from console (#php -q /path/..../script.php) but with cron it not work.

    The problem is that with crontab I get an not found error of PDO class:

    <b>Fatal error</b>: Class 'PDO' not found in <b>/home/user/public_html/test/lib/common/class.PdoWrapper.php</b> on line <b>42</b><br />

    If think that problem is of crontab PATH that it not match PDO class library but I dont understand like I can resolve it
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    What is the exact cron command being used in the crontab? Next, what is line 42 in the /home/user/public_html/test/lib/common/class.PdoWrapper.php file?
     
  3. upsforum

    upsforum Well-Known Member

    Joined:
    Jul 27, 2005
    Messages:
    446
    Likes Received:
    0
    Trophy Points:
    16
    I use ...* * * php -q /path/..../script.php

    ... and I tried with ... * * * /usr/local/bin/php -q /path/..../script.php , in this situation PDO work fine but I get some errors of "file not found" because in script.php the files are include with rel path ("./.......") and not full path ("/home/....")
    I should put the full path and use second command? I wanted to avoid this change.
     
  4. upsforum

    upsforum Well-Known Member

    Joined:
    Jul 27, 2005
    Messages:
    446
    Likes Received:
    0
    Trophy Points:
    16
    in line 42 I have a simple instance of PDO class: mypdo = new PDO('parameters....');
     
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Please put the full path to the script yes. You cannot truncate the path to the script in that manner for a cronjob entry. Cron jobs do not allow relative paths of this sort.

    Also, when the cron command is asked going forward, please do not use examples and provide the actual command used. By shortening it and using examples, it is nearly impossible to know what you had actually used. You can certainly hide the username by putting username in the path, but any other part of the path would need to be the real value being used.
     
  6. upsforum

    upsforum Well-Known Member

    Joined:
    Jul 27, 2005
    Messages:
    446
    Likes Received:
    0
    Trophy Points:
    16
    sorry you're right,

    1) first solution

    * * * * * php -q /home/username/public_html/test/scarico/scarica_trasf_Ordini.php

    I get PDO class not found error

    2) second solution

    /usr/local/bin/php -q /home/username/public_html/test/scarico/scarica_trasf_Ordini.php

    I dont get error PDO class but I get errors for include of others file with relative path ("../include/otherfile.php)
     
  7. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Could you try /usr/bin/php and let us know the results when you use that path?

    If that doesn't work, then the other files being included would need to have the full path's used instead unfortunately.
     
  8. upsforum

    upsforum Well-Known Member

    Joined:
    Jul 27, 2005
    Messages:
    446
    Likes Received:
    0
    Trophy Points:
    16
    I triend with /usr/bin/php but same problem.... I think yours is the best solution, thank you
     
Loading...

Share This Page