2

When running a php script by navigating to the file directly on the server (via the web), everything runs fine.

However, when setting up the same file to run via a cron job, I get the error message:

Call to undefined function mysqli_connect() 

The cron job is set up to run this file, with permission 744:

php -q /home/username/public_html/seafood/php/lobsteremail.php

Any idea why a file might run fine manually but not as part of a cron job?

Justin Mathieu
  • 441
  • 1
  • 8
  • 20
  • 1
    you should enable the mysqli extension in your cli php.ini – Philipp Oct 19 '15 at 19:50
  • Checking my phpInfo page, mysqli is already active (it works fine when running the file manually.) Additionally, inside my php.ini file, I have the following line extension=pdo_mysql.so, which should enable mysqli by default for php 5.4? – Justin Mathieu Oct 19 '15 at 20:22
  • 1
    it's not necessarely the same php.ini for web and cli... check http://stackoverflow.com/questions/10844641/how-to-change-the-path-to-php-ini-in-php-cli-version – Julio Soares Oct 19 '15 at 20:37
  • @JustinMathieu If you solved the issue please let me know. I am facing the same issue. – Tejas Khutale Aug 08 '18 at 13:16

1 Answers1

0

Is your cron job set to run on boot? If so, it cant find mysqli_connect() because mysql is not running yet. Before calling the php script, you need to wait.

Sleep 10 # wait for mysql
php -q /home/username/public_html/seafood/php/lobsteremail.php
pmiguelpinto90
  • 573
  • 9
  • 19