php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35292 Can't connect to local MySQL server through socket
Submitted: 2005-11-19 14:18 UTC Modified: 2005-12-12 15:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dgrimes at scvl dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.4.1 OS: SCO OpenServer
Private report: No CVE-ID: None
 [2005-11-19 14:18 UTC] dgrimes at scvl dot com
Description:
------------
I am having random failure on making a connection to MySQL. This the code used to make the connection and has been for several years.

if (!$this->linkid = mysql_connect($this->host,$this->user,$this->pass))
         DBError(mysql_errno(),mysql_error(),"LINKID-$db",$this->mailerr,$this->sendto);

The following error is returned randomly however it happens usually right after starting apache or after a period of inactivity:

2002 - Can't connect to local MySQL server through socket '/d/mysql/var/mysql.so
ck' (-2146870980)

Starting with version PHP 4.3.0 is when the problem started. Version 4.2.x does not have this problem. I compiled every version until I found where the problem started. I am currently trying to move from 4.0.6 to 4.4.1 but need to get this issue addressed.

My system:
SCO OpenServer 5.0.4 and 5.0.6
MySQL 4.1.15
Apache 1.3.34

Reproduce code:
---------------
if (!$this->linkid = mysql_connect($this->host,$this->user,$this->pass))
         DBError(mysql_errno(),mysql_error(),"$this->linkid LINKID-$db",$this->m
ailerr,$this->sendto);


Expected result:
----------------
I expected to get a resource ID returned.

Actual result:
--------------
2002 - Can't connect to local MySQL server through socket '/d/mysql/var/mysql.so
ck' (-2146870980)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-21 23:21 UTC] dgrimes at scvl dot com
I've done some more research. I took the ext/mysql/php_mysql.c and ext/mysql/php_mysql.h files from version 4.2.3 and copied them into the 4.4.1 tree. Recompiled and installed. The problem has gone away. So, somewhere therein lies the trouble. I'll continue to pursue the cause and if I figure it out I'll let you know what I find. The one question I have is, if I have questions regarding specific functions or variables, can I get answers to those questions?

Thanks,
Dean
 [2005-11-21 23:44 UTC] sniper@php.net
Did you happen to check the diff between those files? It's kinda hard to know WHAT change caused this problem..

Did you use the --with-mysql-sock configure option?
Did you try using the "mysql.default_socket" php.ini option?
 [2005-11-22 00:58 UTC] dgrimes at scvl dot com
I did not use the --with-mysql-sock configure option. I'll try that and see what happens. There were quite a few differences. I'll begin going through them tomorrow by first concentrating on the connect function.

Something I noticed was that 4.2.3 will take a couple of seconds to connect and is successful everytime. 4.4.x gets an error immediately two times in a row and then successfully connects on the third time. This is consistently repeatable by stopping and restarting apache.

So, I'll start first by looking at timeout handling in the connection function. I wish I knew how to get this into the visual debugger so that I could place break points and watch execution. But what I'll do is fopen a file and write the contents of memory variables I deem suspect. It's a slow process but it works.

Thanks,
Dean
 [2005-11-22 16:02 UTC] dgrimes at scvl dot com
Well, compiling with --with-mysql-sock did not make any difference and neither did allowing it to use the default socket. However, I did take the php_mysql_do_connect function out of 4.2 php_mysql.c and put it in place in the 4.4.1 php_mysql.c and then everything worked. So I do believe there may be a timing issue. I'll let you know what I find.

Dean
 [2005-11-22 22:59 UTC] dgrimes at scvl dot com
Here is what I've found so far. There is a new call to a function called mysql_options in the php_mysql_do_connect funciton. When I comment that out, everthing works OK:

      mysql = (php_mysql_conn *) emalloc(sizeof(php_mysql_conn));
      mysql->active_result_id = 0;
#if MYSQL_VERSION_ID > 32199 /* this lets us set the port number */
      mysql_init(&mysql->conn);

            fprintf(xfp,"connect_timeout: %ld\n",connect_timeout);


RIGHT HERE: Line 778 in ext/mysql/php_mysql.c

      if (connect_timeout != -1)
            mysql_options(&mysql->conn, MYSQL_OPT_CONNECT_TIMEOUT, (const char *
)&connect_timeout);

If I comment that line then everything works. Another thing, I tried setting the timeout value to -1 in php.ini file but it's ignored in program. It always has a value of 60. I have verified that the correct php.ini file is being read.

mysql_real_connect returns NULL after setting mysql_options has executed. The MySQL version I'm using is 4.1.16.


      if (mysql_real_connect(&mysql->conn, host, user, passwd, NULL, port, socke
t, client_flags)==NULL) {
#else
      if (mysql_connect(&mysql->conn, host, user, passwd)==NULL) {
#endif
         /* Populate connect error globals so that the error functions can read
them */
         if (MySG(connect_error)!=NULL) efree(MySG(connect_error));
         MySG(connect_error)=estrdup(mysql_error(&mysql->conn));
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error));
#if defined(HAVE_MYSQL_ERRNO)
         MySG(connect_errno)=mysql_errno(&mysql->conn);
#endif


Is it possible that you guys could look at this from this point? If you need me to do anything just let know.

Thanks,
Dean
 [2005-11-22 23:02 UTC] tony2001@php.net
Doesn't look like PHP problem to me.
Please report this issue to MySQL Team (with all the details you've wrote in the last post).
 [2005-11-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-12-12 15:44 UTC] dgrimes at scvl dot com
This did turn out to be a bug in MySQL and is being corrected by the MySQL developers. I want to thank you for all of your help. I have set the status to closed.

Thanks,
Dean
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 11:01:30 2024 UTC