php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49299 misconfigured socket on php cli
Submitted: 2009-08-19 20:29 UTC Modified: 2009-08-20 10:47 UTC
From: david at ols dot es Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2.10 OS: Linux debian
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david at ols dot es
New email:
PHP Version: OS:

 

 [2009-08-19 20:29 UTC] david at ols dot es
Description:
------------
mysql_connect uses wrong socket

Reproduce code:
---------------
#!/usr/local/bin/php -n
<?php
$base="/usr/local/exim";

$lnk=mysql_connect('localhost','root','password');
?>

Expected result:
----------------
script must connect to mysql server

Actual result:
--------------
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

echo "<?php phpinfo(); ?>" | /usr/local/bin/php -n | grep sock

reports:

MYSQL_SOCKET => /tmp/mysql.sock
mysql.default_socket => no value => no value

PHP compiled with ./configure --with-mysql --with-mysql-sock=/tmp/mysql.sock

no default socket configured in php.ini

Apache module version works ok, but same code executed wiht php cli seems to use a socket defined elsewhere

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-20 07:01 UTC] david at ols dot es
sorry, the apache module has the same problem, it only works ok if the socket is defined in php.ini by mysql.default_socket = /tmp/mysql.sock , if left empty trying to connect to localhost produces a "Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/run/mysqld/mysqld.sock' (2)" error altough phpinfo shows MYSQL_SOCKET /tmp/mysql.sock
 [2009-08-20 09:50 UTC] jani@php.net
By default the socket is that (or whatever mysql_config says it is). If you have changed your mysql configuration, then you need to change it in your php.ini as well. No bug here.
 [2009-08-20 10:07 UTC] david at ols dot es
mysql_config correctly reports the socket:

[src]# mysql_config --socket
/tmp/mysql.sock

no change has been made to mysql, no upgrade, no change, nothing, we where only upgrading php, with previous php version all worked ok.

in the other hand php cli with -n does not read at all php.ini
 [2009-08-20 10:27 UTC] david at ols dot es
I found another (ancient) mysql_config which reports the wrong socket, this mysql_config is not the one found by the system (using PATH), so it seems that php is using the wrong mysql_config to get the socket name
 [2009-08-20 10:47 UTC] david at ols dot es
I have removed the mysql_config that reports the wrong socket, compiled php again (also with --with-mysql-sock=/tmp/mysql.sock ) and tested again and the problem is still the same
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 10:01:30 2025 UTC