If I run this code on my workstation in the Execute PHP block provided by the devel module:

echo $_SERVER['argc'];
echo php_sapi_name();

I get:

apache2handler 

On two of my production servers however (one shared hosting and one a dedicated server) I get different results. If I run that on the home page I get:

0cgi

On a URL with one argument, i.e. http://mysite.com/someurl I get

1cgi

And on a URL with multiple arguments, as in http://mysite.com/someurl/x or http://mysite.com/someurl/x/y I get the same thing:

1cgi

phpinfo() says that register_argc_argv is On.

The issue is of course that on any pages except for the home page, devel_query_display doesn't show anything because devel_verify_cli thinks the interface is CLI. AFAICT.

CommentFileSizeAuthor
#16 504510sapi.patch749 bytesJamie Holly

Comments

cpliakas’s picture

We are seeing something similar, and the result is that the devel_verify_cli() function returns false positives in some situations. Specifically, we are seeing that $_SERVER['argc'] is 1 when we are accessing pages via the web on servers where suphp is installed and the php.ini setting register_argc_argv is On. If you change register_argc_argv to Off, the false positives are eliminated as $_SERVER['argc'] is NULL when accessing via the web interface but a positive integer when running via CLI. I can't say with certainty that it is suphp specific, but it appears to us to be the case. This error may be out of the scope of the Devel module, but it is worth noting that devel_verify_cli() doesn't seem to be completely reliable. I understand that the function is forked from Drush, so I am opening an issue there as well pointing to this thread.

As a side note, it goes without saying that the Devel module has been an invaluable resource for development, so thanks for a great module.
~Chris

Anonymous’s picture

Status: Active » Closed (duplicate)

Marking as duplicate of newer issue: #575058: Query log only shown on front page

moshe weitzman’s picture

Status: Closed (duplicate) » Active

reopening this one has better diagnosis

jordanmagnuson’s picture

Same issue (query log only showing on front page, "1cgi" on other pages).

moshe weitzman’s picture

Status: Active » Postponed (maintainer needs more info)

d7 devel is now using drupal_is_cli() which is a core function. does that function work fine for these edge cases? if so, i will backport it to d6 and use it here.

MadtownLems’s picture

I just copied a site from one server to another, and then started dumping query info to benchmark the servers. It was then I realized that I'm having this issue on ONE of the servers only.
Same database, exact same code set, but one dumps the query info on every page, and one just on the front page.

What can I do to help debug this issue? ( or at least get query info! )

MadtownLems’s picture

I copied the site to yet another shared hosting server, and here is the same problem as the first. The site only dumps info on the front page. Is there any way to fix this?

locomo’s picture

I'm experiencing the same behavior with version 6.x-1.19 (query log only showing on front page)

not sure how to troubleshoot - any ideas?

hershel’s picture

Moshe's suggestion was (apparently) to install Drupal 7 in the same environment (perhaps as a subdomain or in a directory) and install the 7.x version of Devel and see if it works there. If it works, then he will try to backport that feature to the 6.x version.

That would be one way to debug.

Mark B’s picture

Perhaps someone with more experience of server configurations can comment on how generally applicable this solution is, but on my host I've been checking whether $_SERVER['HTTP_HOST'] is set - it seems to be set for browser requests, and not set for cli requests.

So I've hacked my 6.x-1.19 devel.module to

function devel_verify_cli() {
  if (php_sapi_name() == 'cgi') {
    return !isset($_SERVER['HTTP_HOST']);
  }

  return (php_sapi_name() == 'cli');
}

If enough people tell me this isn't a completely crazy way to check if we're handling a cli request, I'll roll a patch.

hershel’s picture

Appears to be technically not guaranteed to always work (see http://php.net/manual/en/reserved.variables.server.php ), but in practice most likely it should. I would thus posit that your solution sounds reasonable, Mark B.

moshe weitzman’s picture

Please see #5,

kbahey’s picture

Version: 6.x-1.16 » 6.x-1.x-dev
Component: performance » devel

This is not performance.module related.

Mark B’s picture

re #5, I'm not currently able to deploy the D7 alpha to our production server. However, inspection of the D7 drupal_is_cli function looks as though it is essentially checking exactly the same server variables:

devel.module 6.x:

  if (php_sapi_name() == 'cgi') {
    return (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0);
  }

  return (php_sapi_name() == 'cli');

D7 drupal_is_cli:

return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));

so I would expect the D7 drupal_is_cli function to have exactly the same issue. Perhaps we should instead be looking at porting this patch forward to core.

Jamie Holly’s picture

I have also encounter this problem. If the server is running PHP as a CGI (very common in shared hosting), then the test fails. The reason is you always get one for argc, which is of course q. One possible workaround would be:

return (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0 && !isset($_SERVER['SERVER_ADDR']));

SERVER_ADDR only gets set when PHP is called from a server (HTTP_HOST should also work). I've tested this method on a couple of different shared hosts I have access to and it seems to work fine.

EDIT:

From the D7 function in Comment #14, the D7 function is checking for server software, which is essentially the same thing.

Jamie Holly’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new749 bytes

Attaching a patch just using the D7 solution.

macdonaldj’s picture

thanks, intoxination!

this fixed my issue of the log not showing on all pages.

mikeker’s picture

Verified the fix in #16 works with the Devel 6.x-1.20 release on a standard-issue shared hosting LAMP stack.

Thanks for posting!

moshe weitzman’s picture

I want to use the core drupal_is_cli() function and replicate it in d6. patch core first if its logic is lacking.

moshe weitzman’s picture

Status: Needs review » Needs work
wojtha’s picture

Hmm I'm running 6.x-1.23 where is devel_verify_cli() borrowed from Drupal 7 and I ran in the same issue on Zend Server 5 + Win 7 Pro.

After I reverted the devel_verify_cli() to "borrowed from Drush" state query log display started working again. When I'll have some spare time I'll try to dig deeper.

markchitty’s picture

I was seeing the same issue (i.e. not seeing the query results) on 6.x-1.23 setup on shared hosting (php as cgi). The patch in #16 fixed this issue for me.

yngens2’s picture

Issue summary: View changes

In the newly released 7.x-1.4 version of the module, there is no function devel_verify_cli and the patch naturally doesn't apply anymore.

willzyx’s picture

Status: Needs work » Closed (outdated)

Closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.