Skip to content

Conversation

@tback
Copy link

@tback tback commented Mar 12, 2018

fastcgi_get_status allows to get fpm status information from within php. This allows to implement further status pages in php and to integrate fpm metrics with application metrics.

@tback tback force-pushed the fastcgi-get-status branch from 9bdbb6f to 00a38ff Compare March 12, 2018 19:26
@dzuelke
Copy link
Contributor

dzuelke commented Mar 12, 2018

Just one note, and probably trivial to add: I think that for completeness' sake, it should then also be possible to access the current process' FPM pool name and child PID (although posix_getpid can be used for that, the extension may not be enabled) for e.g. logging purposes, otherwise it's a little useless to log certain metrics without being able to correlate events.

@tback
Copy link
Author

tback commented Mar 13, 2018

Thanks for the input @dzuelke. Are you suggesting a separate function to return the pool name or do you want the pool name included in the results of fastcgi_get_status()? The latter is implemented already.

getmypid() returns the pid of the current child and is available on all plattforms. Maybe that is sufficient?

@dzuelke
Copy link
Contributor

dzuelke commented Mar 13, 2018

Ah, never mind then, @tback :)

👍


static const zend_function_entry cgi_fcgi_sapi_functions[] = {
PHP_FE(fastcgi_finish_request, NULL)
PHP_FE(fastcgi_get_status, NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably go with fpm_get_status as this more fpm related...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 8ade2f5


/* {{{ proto array fastcgi_get_status
* Returns the status of the fastcgi process manager */
PHP_FUNCTION(fastcgi_get_status)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have a function that would just fill the supplied zval and PHP_FUNCTION in fpm_main.c that would call it. It means function like:

int fpm_status_export_to_zval(zval *status);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 979cec1

if (!scoreboard_p->procs[i] || !scoreboard_p->procs[i]->used) {
continue;
}
proc = *scoreboard_p->procs[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is actually safe to do without the lock as technically some value could be changed by other process during this copy. I'm aware that this is also done in fpm_status_handle_request for full syntax but not sure if it's correct in there too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meaning it might be a bug in there too... :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It struck me too when copy pasting it. I've been reading through the code over the past days.
I assume the worst possible result right now is an inconsistent reading, like number of active processes not being in sync with detailed process stats.
I assume the safe way to do it would be to lock the scoreboard, then iterate through the procs and copy (lock copy unlock) them one by one and only then unlocking the scoreboard.
Is this the path of action you're suggesting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that would be safe as we can't just copy the whole scoreboard and procs in one go (each proc can be locked individually..).

It would be good to introduce a new function fpm_scoreboard_copy that would allocate new scoreboard and copy all data into it (first locked scoreboard data and then iterate and copy the procs as you suggested). I think this might make sense to do in separate PR and use it for full syntax. The reason is that this part could be back ported to the stable branches as it seems like a bug to me. This PR can be then based on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #3185 and implemented safe access in 9eb8db6

{
int error = fpm_status_export_to_zval(return_value);
if(error){
RETURN_FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should verbose this error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do that

PHP_FUNCTION(fpm_get_status) /* {{{ */
{
int error = fpm_status_export_to_zval(return_value);
if(error){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS: missing spaces... If you don't need to use error later then this should do:

if (fpm_status_export_to_zval(return_value)) {

struct fpm_scoreboard_proc_s procs[scoreboard.nprocs];

struct fpm_scoreboard_proc_s *proc_p;
for(i=0; i<scoreboard.nprocs; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs: for () {}

--TEST--
FPM: Test fpm_get_status function
--SKIPIF--
<?php include "skipif.inc"; ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require is preferable, as is safer 🛡️

@tback tback changed the title Implement function to get fpm status from php fastcgi_get_status WIP: Implement function to get fpm status from php fastcgi_get_status Mar 19, 2018
@tback
Copy link
Author

tback commented Mar 19, 2018

This will have to wait until I implemented fpm_copy_scoreboard.

@dzuelke
Copy link
Contributor

dzuelke commented Jun 25, 2018

Is this something we could get into PHP 7.3, together with #2458, @tback and @bukka? Would make a lot of sense IMO to have access to the pool name info for logging in environments where (using that other PR) "... child said" stdout/stderr decoration is disabled.

@php-pulls
Copy link

Comment on behalf of bukka at php.net:

Merged in 140def4 and test migrated in f86f3ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants