cron + Call to undefined function mysql_connect()

pppplus

Verified User
Joined
Dec 19, 2008
Messages
528
Hi

I've another problem after upgrading to php 5.6

mysql_connect does not work anymore with cron

My installation :

Centos 6.8
php1_release=5.6
php1_mode=php-fpm
php2_release=5.3 (no more used)
php2_mode=php-fpm


If I execute from ssh, it works :
php /home/castor/domains/mydomain.com/cron/nettoyage.php

But from cron, I've the error : Call to undefined function mysql_connect()


I read I have to add
extension=msql.so

But I find it strange (and it has no effect)
 
mysql_* was deprecated in PHP 5.5.0. I can only guess that your cron is refusing to continue when the script throws a warning.

Try to run it with the php 5.3 binary and see if it will work.
 
When I run this :

Code:
/usr/local/php56/bin/php -r "mysql_connect();"

I've got:

Code:
PHP Warning:  mysql_connect(): Access denied for user ''@'localhost' (using password: NO) in Command line code on line 1

on my server with a default PHP 5.6:

Code:
# /usr/local/php56/bin/php -i | grep configure | grep -o "\-\-with\-mysql[^\']*"
--with-mysql=mysqlnd
--with-mysql-sock=/var/lib/mysql/mysql.sock
--with-mysqli=mysqlnd


And what you get as a result for the both commands?

Code:
/usr/local/php56/bin/php -r "mysql_connect();"
Code:
/usr/local/php56/bin/php -i | grep configure | grep -o "\-\-with\-mysql[^\']*"
 
Thanks for your help

Code:
# /usr/local/php56/bin/php -r "mysql_connect();"
PHP Warning:  mysql_connect(): Access denied for user ''@'localhost' (using password: NO) in Command line code on line 1


Code:
# /usr/local/php56/bin/php -i | grep configure | grep -o "\-\-with\-mysql[^\']*"
--with-mysql=mysqlnd
--with-mysql-sock=/var/lib/mysql/mysql.sock
--with-mysqli=mysqlnd
 
So, it's the same, and your PHP is installed with support of "mysql_connect()".

My guess is that the cron script is using PHP built either from yum/rpm or by other means, so try and find out which PHP it is using. Is the file open-source? Or encoded?


Code:
rpm -qa | grep php
Code:
head [COLOR=#333333]/home/castor/domains/mydomain.com/cron/nettoyage.php -n1
[/COLOR]
Code:
php -v && php --ini
 
Thanks

Code:
[root]# rpm -qa | grep php
php-odbc-5.3.3-48.el6_8.x86_64
php-pear-1.9.4-5.el6.noarch
php-pdo-5.3.3-48.el6_8.x86_64
php-cli-5.3.3-48.el6_8.x86_64
php-common-5.3.3-48.el6_8.x86_64
php-imap-5.3.3-48.el6_8.x86_64
php-pecl-geoip-1.0.8-3.el6.x86_64

[root]# head /home/castor/domains/mydomain.com/cron/nettoyage.php -n1
#!/usr/local/bin/php

[root]# php -v && php --ini
PHP 5.6.30 (cli) (built: Mar 10 2017 13:03:28)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v6.0.9, Copyright (c) 2002-2016, by ionCube Ltd.
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
Configuration File (php.ini) Path: /usr/local/php56/lib
Loaded Configuration File:         /usr/local/php56/lib/php.ini
Scan for additional .ini files in: /usr/local/php56/lib/php.conf.d
Additional .ini files parsed:      /usr/local/php56/lib/php.conf.d/10-directadmin.ini,
/usr/local/php56/lib/php.conf.d/50-webapps.ini,
/usr/local/php56/lib/php.conf.d/90-custom.ini
 
You should remove the rpms:

php-odbc-5.3.3-48.el6_8.x86_64
php-pear-1.9.4-5.el6.noarch
php-pdo-5.3.3-48.el6_8.x86_64
php-cli-5.3.3-48.el6_8.x86_64
php-common-5.3.3-48.el6_8.x86_64
php-imap-5.3.3-48.el6_8.x86_64
php-pecl-geoip-1.0.8-3.el6.x86_64


If for any reason you can not remove them, then try and specify a full path on cron for PHP. It seems that cron uses php from /usr/bin/:

Code:
/usr/local/php56/bin/php /home/castor/domains/mydomain.com/cron/nettoyage.php
 
Yes ! You're right, one more time !!

With /usr/local/php56/bin/php , it works;

I will remove rpms.

Thanks you very much Alex !!
Best regards
 
You should remove the rpms:

php-odbc-5.3.3-48.el6_8.x86_64
php-pear-1.9.4-5.el6.noarch
php-pdo-5.3.3-48.el6_8.x86_64
php-cli-5.3.3-48.el6_8.x86_64
php-common-5.3.3-48.el6_8.x86_64
php-imap-5.3.3-48.el6_8.x86_64
php-pecl-geoip-1.0.8-3.el6.x86_64

Hi Alex

I'm not sure about what I can do exactly.

- pear 1.9.4 seems the actual pear, so I suppose I do not remove it.
- php-pecl-geoip-1.0.8-3.el6.x86_64 is what I just install today with your help ?


php-odbc-5.3.3-48.el6_8.x86_64
php-pdo-5.3.3-48.el6_8.x86_64
php-cli-5.3.3-48.el6_8.x86_64
php-common-5.3.3-48.el6_8.x86_64
php-imap-5.3.3-48.el6_8.x86_64

These 5 lines seems to be attached to php 5.3
So I can remove them ? right ?

To remove, I simply run :
yum remove php-odbc
yum remove php-pdo
yum remove php-cli
yum remove php-common
yum remove php-imap


Thanks for your reply.
 
On a server with Directadmin by default you don't need to have any php-* packages and php-pear as well. Custombuild installs PHP with pecl and pear:

Code:
# ls -1 /usr/local/php*/bin/pear
/usr/local/php53/bin/pear
/usr/local/php54/bin/pear
/usr/local/php55/bin/pear
/usr/local/php56/bin/pear
/usr/local/php70/bin/pear
/usr/local/php71/bin/pear

Run:

Code:
yum remove php-*

to remove php-* RPM packages. It will ask a confirmation if you run it without -y flag. So it's safe to run and see a list of packages to be removed.
 
Last edited:
Back
Top