Server has broken PHP functions

7 posts by 3 authors in: Forums > CMS Builder
Last Post: June 25, 2018   (RSS)

By kitsguru - June 12, 2018 - edited: June 12, 2018

I am getting the following errors using CMSB 3.12 on one client with php 5.6. Other clients on the same server are not seeing this error nor are those using php 7.0. I am using uptimerobot and this is generating errors every 5 minutes. Is there a way to suppress these messages as they are more or less meaningless and just fill up the log.

Also, if possible, I would like to get to the bottom of why it is occurring and fix it permanently. I can reproduce it by using "curl -I domain" on my local development machine.

#62 - E_USER_ERROR: There was an error creating the list field 'category'.

MySQL Error:

NOTE: Server has broken PHP functions: print_r, ob_get_clean. This is sometimes caused by HTTP HEAD requests. Error occurred during a HTTP HEAD request from: 24.69.45.xxx

/home/xxx/public_html/cmsb/lib/schema_functions.php (line 379)
https://example/index.php


    
#61 - E_WARNING: mysqli::query(): Empty query

NOTE: Server has broken PHP functions: print_r, ob_get_clean. This is sometimes caused by HTTP HEAD requests. Error occurred during a HTTP HEAD request from: 24.69.45.xxx

/home/xxx/public_html/cmsb/lib/schema_functions.php (line 373)
https://example/index.php

Jeff Shields

By leo - June 13, 2018

Hi Jeff,

Do you know what are the option values you set for the list field "category"? For example is it text or from another table or from a mysql query? You should be able to check the setting under the section editor and click modify for the "category" field. I think the errors show up because getListOptionsFromSchema() function didn't process correctly and threw an error.

Leo - PHP Programmer (in training)
interactivetools.com

By Dave - June 14, 2018

Hi Jeff, 

You can disable that function by adding this code to the top of /lib/errorlog_functions.php

// enable error logging
if (isInstalled()) {
  if ($_SERVER['REQUEST_METHOD'] != 'HEAD') { // prevents HEAD request errors being logged from _errorlog_getBrokenPhpFunctionsWarning()
    errorlog_enable();
  }
}

I'll add that code (commented but there) for future releases.  

The underlying issue is that when the server receives a HEAD request some of the PHP functionality doesn't work correctly.  We've never been able to identify the root cause of this but it's likely related to something to do with the server configuration.  The above change just disables the logging of the errors.  There will still be errors caused by the software not operating correctly because PHP functions aren't working.

Hope that helps, let me know any questions!

Dave Edis - Senior Developer
interactivetools.com

By kitsguru - June 22, 2018

I had a few hours to investigate this a bit,

The problem does not exist with php 7+ because php does not get executed at all when only a head request is sent.

With php 5.6, the code is executed. I added the following to the beginning of my initialization sequence before calling the viewer functions.

if ($_SERVER['REQUEST_METHOD'] === 'HEAD') {
    header('html/text');
    exit;
}

Everything worked as expected.

I used Xdebug to show that this line does not run in 7+ and has no negative impact on 5.6 as the exact same header is returned with or without this snippet.

Jeff Shields

By Dave - June 25, 2018

Ok, can you let me know if that causes any issues over time? 

My concern with disabling HEAD requests is that it's a valid part of the HTTP protocol, so browsers might send a HEAD request to see if a resource has changed without needing to get the content.  

See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

9.4 The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

So it should execute PHP regardless.  HEAD requests are also often used by server uptime checkers, etc.

In any case, let me know how it goes.  

Dave Edis - Senior Developer
interactivetools.com

By kitsguru - June 25, 2018

My solution does not violate the principle in that it returns the headers and stops so no message body is sent.

Jeff Shields