-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add syslog's ident and facility parameters to config #2701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add syslog's ident and facility parameters to config #2701
Conversation
@bukka Should the existing support for |
93d2765
to
393e350
Compare
@pprindeville This is nice but this won't give us an ability for setting an external server without going through the system logger. As I said I really like what nginx does as it re-implements the syslog client completely and allows direct remote logging. It has got many advantages and it's more flexible solution that could be especially useful for future improvements (especially in FPM where we could make things work in more non-blocking way...) |
That being said I think it would be good to at least have this if we don't have an alternative solution before 7.3 feature deadline (this is a new feature so it's just for master which means 7.3). |
393e350
to
a56e2d9
Compare
@bukka Going directly to an external logger is, in some circles, considered a liability. One of the requirements of the Red Book section "2.2.2.2 Audit" is for centralized logging and collection, as it makes it easier to enforce access control, log rotation, etc. if it goes through a centralized mechanism. Allowing individual apps or subsystems to defeat that would be counter to the the requirements of Red Book. I would hope that this mechanism is configurable at build-time so that one could build PHP without logging bypass. |
@bukka These are really orthogonal issues. My fix is to make the usage of the syslog API more complete. Yours is an entire alternative to it. It's not an "either/or" but rather "and". |
Amended: if we call |
@pprindeville There are many use cases when direct remote logging is useful especially when it comes to containers. For example you might want to run Docker containers for rsyslog and another for PHP and log into the rsyslog container. Of course I'm sure that there are many more examples and I also believe that it wouldn't be in nginx if it was pointless :). The fact is that Red Book was released in 1987 and lots of things have changed since then. Personally I see the future of PHP (namely FPM) running as a single app inside the containers and that's why I'm looking to the solutions how to improve logging in there because currently it there are lots of issues and limitations. |
@bukka Can you please explain to me the order of .ini and .conf files read by php-cli vs. php-fpm? Or point me at where the differences are explained? Because with this change, it seems like php-fpm is picking up the |
a56e2d9
to
d1a74f4
Compare
@pprindeville The main ini file (e.g. php.ini) is loaded during the startup in fpm which happens when you start master. You can find it in
FPM allows to redefine the ini values which is described in here Lines 394 to 417 in ebb3396
and it happens during the child init (search for fpm_php_init_child in fpm_php.c where you can see the logic - fpmi_php_apply_defines is the main function for that) which happens when the new child process is created. GDB should help you with the rest. The redefinition is after fork so it's useful to set follow-fork-mode to child and detach-on-fork to off ;) |
@bukka Thanks, that helped. I had forgotten to set the |
@nikic Can you please assign a reviewer? |
main/php_syslog.c
Outdated
@@ -37,6 +38,8 @@ | |||
#define syslog std_syslog | |||
#endif | |||
|
|||
zend_bool have_called_openlog = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not thread safe, thus it should go into globals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not thread safe, thus it should go into globals.
Not sure I understand. What's an example of a global variable that I can use as an example? Are you talking about SG()
and sapi_globals
or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, something in this direction. Perhaps core globals were more suitable, as it's not something SAPI specific. Another option in PHP 7 is using ZEND_TLS, but should check whether its usage were suitable in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't core globals for configuration state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not thread safe, thus it should go into globals.
@weltling Done
@pprindeville new features for feature frozen branches are handled on case by case base. As @bukka works on a patch for this for quite some time already, it probably would make sense you to coordinate with him. IMO the remote logging solution he suggests is promising for both functionality and maintenance. Thanks. |
0cf970b
to
a34f3c1
Compare
Not sure what to do about the Travis failure. Looks like the build is taking too long and that master has some unrelated test case failures going on. |
Is anything else needed at this point? |
Zend/zend_globals.h
Outdated
@@ -127,6 +127,8 @@ struct _zend_compiler_globals { | |||
zval **static_members_table; | |||
int last_static_member; | |||
#endif | |||
|
|||
zend_bool have_called_openlog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this need to in CG? PG maybe better? thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I asked and no one answered...
Isn't core_globals
for configurable state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CG is for compiler globals, PG is more suitable in this case IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pprindeville This really should be in PG...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pprindeville This really should be in PG...
Where/how do you initialize a core_globals
variable that's not user settable? What's the appropriate modifiable
value?
I think I've got the correct STD_PHP_INI_BOOLEAN(...)
for have_called_openlog
but would appreciate someone else giving it a quick look. Thanks
Hi CG is compiler globals |
@KalleZ: okay, so where should I put |
It's a PHP specific thing so leave it in PG, Note that only engine and core language is Zend, whereas PHP is sapis, standard libraries and extensions |
Okay. No further rework required then? When might it merge? Thanks |
9d3931e
to
59d7164
Compare
Any other issues? |
ext/standard/syslog.c
Outdated
@@ -152,6 +152,7 @@ PHP_FUNCTION(openlog) | |||
RETURN_FALSE; | |||
} | |||
openlog(BG(syslog_device), option, facility); | |||
PG(have_called_openlog) = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest one small improvement. Maybe we could introduce php_openlog
with the same args as openlog that would just call openlog and set PG(have_called_openlog)
so it's done internally in that function. Then it would be used in here and fpm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then... syslog()
would need to call php_openlog()
... What would that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm saying is to just replace:
openlog(BG(syslog_device), option, facility);
PG(have_called_openlog) = 1;
with
php_openlog(BG(syslog_device), option, facility);
and implement php_openlog as
void php_openlog(const char *ident, int option, int facility)
{
openlog(BG(syslog_device), option, facility);
PG(have_called_openlog) = 1;
}
Then you also replace it in other place. It's just a wrapper as you use the same pattern in 2 other places - no change in your logic...
@pprindeville Just commented about two things and then it should be good if all tests are fine (I mean the manual testing that I plan to do). Sorry for the late requests, it's just because I finally found time to look into this and think about it... :) |
e07c1d8
to
fe1163e
Compare
@@ -95,10 +95,6 @@ void vsyslog(int priority, const char *message, va_list args) | |||
DWORD evid; | |||
wchar_t *strsw[2]; | |||
|
|||
/* default event source */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no calls to vsyslog()
(directly), it all flows through php_syslog()
so there's no way to reach here without openlog()
having been called first (and thereby setting log_source
).
BTW, what's the difference between |
@pprindeville PW32G is "PHP Win32 Globals", so only globals that do stuff specifically for Windows, where as PG is simply "PHP Globals", as in globals that interact within the PHP layer of the PHP stack (like ini settings) |
Got it. Well, hopefully everyone is okay with the latest version? |
Uh...
Pretty sure this has nothing to do with these changes. Also reasonably sure this was working yesterday. |
If anyone is waiting on something from me to move this forward, please call it out. |
fe1163e
to
69b46df
Compare
So... has this fix missed 7.3.0 or am I mistaken? |
@pprindeville Nope, hasn't missed 7.3 (yet...) Projected release schedule can be found here: https://wiki.php.net/todo/php73#timetable |
Well, it's getting close. If we don't make Alpha 3 (in 3 weeks) it looks like we'll have missed the feature freeze. |
The CI builds are failing due to unrelated errors, btw. |
@bukka Are there any blocking review comments still? You're showing (currently) as requesting changes. |
php.ini-development
Outdated
@@ -577,6 +577,8 @@ html_errors = On | |||
;error_log = php_errors.log | |||
; Log errors to syslog (Event Log on Windows). | |||
;error_log = syslog | |||
;syslog.ident = php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment line (just short description and that it applies only if error_log is syslog) for each new ini and also update php.ini-production with the same setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
Done!
I did a little bit of testing and all seems good. Could you just update ini files and I will try to merge it tomorrow or sometimes next week. |
69b46df
to
a490552
Compare
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
a490552
to
a667e38
Compare
Comment on behalf of bukka at php.net: Marge in 2475337 |
Awesome, thanks! |
You might want to be able to set the ident (
syslog.ident
) and facility (syslog.facility
) before a single line of scripting gets executed... especially if you're debugging code and it might crash before it has a chance to callopenlog()
, etc.