Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When running Drupal from the command line REMOTE_ADDR isn't populated thus calls to ip_address can cause a PHP notice.
Comment | File | Size | Author |
---|---|---|---|
#5 | drupal-1882556-5-remote-addr-notice-D8.patch | 575 bytes | mikeytown2 |
#1 | drupal-1882556-1-remote-addr-notice-D6-do-not-test.patch | 631 bytes | mikeytown2 |
#1 | drupal-1882556-1-remote-addr-notice-D7-do-not-test.patch | 549 bytes | mikeytown2 |
#1 | drupal-1882556-1-remote-addr-notice-D8.patch | 569 bytes | mikeytown2 |
Comments
Comment #1
mikeytown2 CreditAttribution: mikeytown2 commentedComment #3
mikeytown2 CreditAttribution: mikeytown2 commented#1: drupal-1882556-1-remote-addr-notice-D8.patch queued for re-testing.
Comment #5
mikeytown2 CreditAttribution: mikeytown2 commentedforgot to do git pull for 8.x
Comment #6
kscheirerI like, this looks like an easy fix.
Comment #7
Dries CreditAttribution: Dries commentedI'm not sure we can automatically asume 127.0.0.1 (localhost) if that server variable isn't set. It is probably better not to return an IP address, rather than returning an incorrect one.
Comment #8
mikeytown2 CreditAttribution: mikeytown2 commentedWe automatically assume 127.0.0.1 in drupal.sh. If this is still a bad assumption I'll re-work this patch :)
Comment #9
kris-o3 CreditAttribution: kris-o3 commentedis this not the exact problem that drupal_override_server_variables was designed to solve?
Comment #10
sunip_address() no longer exists.
Comment #11
david_garcia CreditAttribution: david_garcia commentedSorry to reopen, isn't this still an issue in D7?
Comment #12
danreb CreditAttribution: danreb commentedI've seen this in error_log but in line 2916 and 1616 as shown in my apache error log.
Comment #13
susannecoates CreditAttribution: susannecoates commentedI'm seeing this issue too when bootstrapping Drupal 7 in a php script run on the command line.
A simple code snippet to illustrate:
Executed on the CLI with:
php test.php /srv/websites/susanne.test
Produces the following output:
Comment #14
BD3 CreditAttribution: BD3 commentedMy issue was that I had a Drupal 6 site with a cron job running from cPanel. Well when a new Drupal 7 site was launched, I never removed the cron script from cPanel which was causing this error in the Apache logs every time it was ran. Removing the cron fixed this issue as I was running cron from Drupal 7 UI.
Just thought I would post here for anyone else having the same issue.
Comment #15
newswatch CreditAttribution: newswatch commentedI followed #14. It seems running cron from Cpanel was causing the problem.
Comment #16
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI do agree with Dries, I think returning '' would be better to avoid side effects and have the same behavior. Just without the warning. On the other hand you should really use drupal.sh to try to do command line processing, so it could also be considered won't fix.
Hmmm, okay so what about:
Comment #17
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedAs @kris-o3 mentioned, in scenarios like #13 the
drupal_override_server_variables()
should be used before bootstraping Drupal and it should fix the problem.The second mentioned scenario (where the cron.php is run via command line php) can be fixed, but I don't think that the approach with NULL would work. We have multiple tables with hostname column defined as:
So it explicitly says NOT NULL. For example the Poll module is inserting the output of the
ip_address()
directly to the database, so this query:would throw a PDOException (at least on some DB engines like PostgreSQL):
The same problem can be with the accesslog and other tables/modules. So I think we have two options:
1. Replace the NULL with an empty string:
2. Won't fix this issue (see #16).