0
votes

I am encountering a very strange problem after moving to PHP55.

I have a working environment both locally and deployed on PHP. After following instructions sent by Google on migrating to PHP55:

To take advantage of these new features, find your ‘app.yaml’ file and change the line that reads runtime: php to runtime: php55

The new functionality will automatically be enabled in the local development server, and in production once your application is deployed. You will be able to switch back to the old runtime at any time for the next two months by reverting the configuration in your app.yaml file. Some features such as cURL support may require additional configuration in order to be enabled.*

I hit the famous Error establishing a database connection error.

As soon as I revert the PHP55 back to PHP in my app.yaml file, the error goes away and the webpages load again.

Any feedback is greatly appreciated. I can share the wp-config.php if needed.

Here is the entries in app.yaml :

application: sxxxx-xxxxx version: 5 runtime: php55 api_version: 1 threadsafe: yes

handlers: - url: /(..(htm|html|css|js))$ static_files: \1 upload: ..(htm|html|css|js)$ application_readable: true

- url: /wp-content/(.*\.(ico|jpg|png|gif))$
  static_files: wp-content/\1
  upload: wp-content/.*\.(ico|jpg|png|gif)$
  application_readable: true

- url: /(.*\.(ico|jpg|png|gif))$
  static_files: \1
  upload: .*\.(ico|jpg|png|gif)$

- url: /wp-admin/(.+)
  script: wp-admin/\1
  secure: never

- url: /wp-admin/
  script: wp-admin/index.php
  secure: never

- url: /wp-login.php
  script: wp-login.php
  secure: never

- url: /wp-cron.php
  script: wp-cron.php
  login: admin

- url: /xmlrpc.php
  script: xmlrpc.php

- url: /wp-(.+).php
  script: wp-\1.php

- url: /(.+)?/?
  script: index.php

=============

Here is my unchanged wp-config.php which works with php in app.yaml, but with php55 in app.yaml, gives me the Error :

if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {

    /** Google App Engine Settings */
    define('DB_NAME', 'sadhusanga');
    define('DB_USER', 'root');
    define('DB_PASSWORD', '');
    define('DB_HOST', ':/cloudsql/sadhu-sanga:gaura');

}
else
{

    /** Local Settings */
    define('DB_NAME', 'sadhusanga');
    define('DB_USER', 'root');
    define('DB_PASSWORD', 'xxxxxxxx');
    define('DB_HOST', 'localhost');

}
1
Obviously we would need some code. How are we meant to help otherwise? Are we meant to guess? - arkascha
I have added the code within app.yaml and wp-config.php. Please let me know if you would like to know about any other configuration or settings. - Harsha Holla Karkada
Sorry, but that does not help. What I asked for is the code that actually establishes the connection. Since that step fails according to you it makes sense to take a look at it. We are not interested in your login credentials. - arkascha
We are using wordpress with google app engine. There is no special code we have written to establish this connection except adding entries in the wordpress config file. What code are we talking about here? - Harsha Holla Karkada
That is for example interesting, because you never mentioned before that you are using wordpress. Wordpress opens the database connection, I guess, so it is the wordpress code that fails. Did you ask in their forums? They should know if there is an issue with php-5.5 and how to solve it. We cannot say why it might fail without the code, sorry again. And it makes no sense to expect from us that we dig through the wordpress code you do not want to post here :-) - arkascha

1 Answers

0
votes

I'll take a stab at this.

Wordpress will use MySQLi when it detects that you are using PHP >= 5.5. See https://github.com/WordPress/WordPress/blob/master/wp-includes/wp-db.php#L627 for what I mean. WP attempts to duplicate the socket detection that mysql_real_connect makes, and it does an okay job with your existing DB_HOST configuration; however, it leaves the host variable as an empty string rather than NULL after moving it to socket. mysqli_real_connect requires NULL or "localhost" for the hostname when using a socket connection. See http://php.net/manual/en/mysqli.real-connect.php about what I mean.

Doing a var_dump on the variables after the WP socket detection gives us:

array(4) { ["initial_host"]=> string(30) ":/cloudsql/project-id:instance" ["new_host"]=> string(0) "" ["port"]=> NULL ["socket"]=> string(29) "/cloudsql/project-id:instance" }

I just ran a test on my GAE app and it did throw a DB connection error because of the empty string for hostname.