[ZBX-12476] PHP UserParameter hangs under PHP-5.3.3 but not PHP >= 5.4 Created: 2017 Aug 05  Updated: 2017 Aug 07  Resolved: 2017 Aug 06

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G), Proxy (P), Server (S)
Affects Version/s: None
Fix Version/s: None

Type: Problem report Priority: Major
Reporter: Jim Dutton Assignee: Unassigned
Resolution: Won't fix Votes: 0
Labels: externalchecks, userparameters
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS-6.9, three hosts:
a) Zabbix-2.2.18, PHP-5.3.3
b) Zabbix-2.4.8, PHP-5.3.3, PHP-5.6.32
c) Zabbix-3.2.6, PHP-5.6.31

RHEL-7.3, one host
a) Zabbix-2.4.8, PHP-5.4.16



 Description   

Using simple PHP script as UserParameter,

UserParameter=local.php.test,php -f /var/tmp/stdout.tester.php
<?php 
   date_default_timezone_set("America/Chicago");
   $count=fwrite(STDOUT,strftime("%c"));
   exit;
?>

the test (zabbix_agentd -t local.php.test) hangs under PHP-5.3.3 but works with PHP >=5.4.

Significant tail-end portion of strace Zabbix-2.1.18/2.4.8, PHP-5.3.3

alarm(3)                                = 0
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f6ce1aeda90) = 3215
close(4)                                = 0
read(3, 0x7ffc3cf7f210, 4095)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_STOPPED, si_pid=3215, si_status=SIGTTOU, si_utime=0, si_stime=0} ---
read(3, 0x7ffc3cf7f210, 4095)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL, si_value={int=22, ptr=0x16}} ---
rt_sigreturn()                          = -1 EINTR (Interrupted system call)
close(3)                                = 0
kill(4294964081, SIGTERM)               = 0
wait4(3215, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGTTOU}], WSTOPPED|WCONTINUED, NULL) = 3215
wait4(3215, ^CProcess 3214 detached
 <detached ...>
[root@newzabbix tmp]# zabbix_agentd [3214]: Warning: Got signal [signal:2(SIGINT),sender_pid:0,sender_uid:0,reason:128]. Exiting ...
zabbix_agentd [3214]: Zabbix Agent stopped. Zabbix 2.2.18 (revision 67443).

Process hangs and has to be manually terminated (crtl-c).

strace of success under Zabbix-2.4.8, PHP >= 5.4

alarm(3)                                = 0
pipe([3, 4])                            = 0
write(1, "local.php.test                  "..., 45local.php.test                               ) = 45
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f112fb18a90) = 3708
close(4)                                = 0
read(3, "Sat Aug  5 00:00:10 2017", 4095) = 24
read(3, "", 4095)                       = 0
close(3)                                = 0
wait4(3708, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WSTOPPED|WCONTINUED, NULL) = 3708
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3708, si_status=0, si_utime=0, si_stime=0} ---
alarm(0)                                = 3
write(1, " [t|Sat Aug  5 00:00:10 2017]\n", 30 [t|Sat Aug  5 00:00:10 2017]
) = 30
exit_group(0)                           = ?
+++ exited with 0 +++


 Comments   
Comment by Glebs Ivanovskis (Inactive) [ 2017 Aug 05 ]

If you simply run your script from command line, does it work as it should on all PHP versions?

Comment by Jim Dutton [ 2017 Aug 05 ]

Yes - execution of the PHP UserParameter script works just fine from the command line as a PHP invocation. The following document fragment for one of my SourceForge projects notes this issue:

=========================
It appears that Zabbix, of any release, using PHP for UserParameter scripts may encounter a breaking point if the version of PHP is 5.3.3 (or < 5.4). Using such a script will cause the zabbix_agentd process to hang. For implementors of Zabbix-HDD, there are three alternatives:

1. install PHP >= 5.4

2. don't use PHP based UserParameter scripts (eg; stick to (Unix) shell scripts)

3. use a “sneaky proxy” by putting the PHP UserParameter script under Apache (HTTPD) with built-in PHP support and using curl to invoke the PHP UserParameter script and successfully process it, such as

1. UserParameter=hw.disk.discovery,/usr/bin/curl --raw --silent http://localhost/zabbix-php/<script filename>

= = = = = = = = = = = = = = = = =

Apache configuration used:


Alias /zabbix-php "/var/www/html/zabbix-php"
<Directory "/var/www/html/zabbix-php/">
Allow from all
</Directory>
AddType application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>


Two simple PHP scripts to use for testing (“stdout.tester.php”, ”stdout.tester2.php”)


<?php
echo "strftime: " . strftime("%c");
exit;
?>



<?php
$lastline=exec("cat /proc/partitions",$ProcPartARRAY,$RC);
$count=fwrite(STDOUT,print_r($ProcPartARRAY));
exit;
?>


Sample result (“local.php.test” => “stdout.tester.php”):

zabbix_get -s 127.0.0.1 -k local.php.test
strftime: Sat Aug 5 01:49:38 2017

=========================

NOTE: this issue with PHP-5.3.3 does not appear to affect the Zabbix "front-end" (web pages). Only the "child process" environment that is created/used for UserParameter scripts.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Aug 05 ]

When Zabbix hangs with PHP-5.3.3 is there any hanging or zombie processes related to your script?

Zabbix receives SIGCHLD while doing read() meaning that script terminated, but read() does not unblock meaning that file descriptor Zabbix is reading from wasn't closed by all processes having it open. Then finally read() is interrupted by SIGALRM, Zabbix tries to kill() child and blocks in waitpid(). Maybe it's a sort of misbehaviour on PHP side, but Zabbix should definitely be robust enough to handle it. waitpid() must be executed within timeout.

Comment by Jim Dutton [ 2017 Aug 06 ]

No zombie processes found.

List of running agentd tasks:
=====================================

zabbix    2490     1  0 15:46 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    2491  2490  0 15:46 ?        00:00:01 /usr/local/sbin/zabbix_agentd: collecto
r [idle 1 sec]
zabbix    2492  2490  0 15:46 ?        00:00:00 /usr/local/sbin/zabbix_agentd: listener
 #1 [waiting for connection]
zabbix    2493  2490  0 15:46 ?        00:00:00 /usr/local/sbin/zabbix_agentd: listener
 #2 [waiting for connection]
zabbix    2494  2490  0 15:46 ?        00:00:00 /usr/local/sbin/zabbix_agentd: listener
 #3 [waiting for connection]
zabbix    2495  2490  0 15:46 ?        00:00:01 /usr/local/sbin/zabbix_agentd: active c
hecks #1 [idle 1 sec]
postfix   3460  1964  0 17:21 ?        00:00:00 pickup -l -t fifo -u
root      3512  2405  0 17:29 pts/1    00:00:00 vi zabbix_agentd.conf
root      3523  2403  0 17:30 pts/0    00:00:00 zabbix_agentd -t local.php.test
root      3524  3523  0 17:30 pts/0    00:00:00 /usr/bin/php -f /var/tmp/stdout.tester.
php

=====================================

top (partial) output
=====================================

top - 17:49:58 up  2:09,  4 users,  load average: 0.08, 0.07, 0.02
Tasks: 163 total,   1 running, 161 sleeping,   1 stopped,   0 zombie
Cpu(s):  0.7%us,  0.4%sy,  0.0%ni, 98.5%id,  0.4%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1020052k total,   895756k used,   124296k free,    50088k buffers
Swap:  2064380k total,        8k used,  2064372k free,   237096k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                   
    7 root      20   0     0    0    0 S  1.8  0.0   0:02.79 events/0                  
 2366 root      20   0  292m  13m 9912 S  1.8  1.3   0:00.97 gnome-terminal            
 2491 zabbix    20   0 78620 1096  592 S  1.8  0.1   0:01.93 zabbix_agentd             
 3997 root      20   0 17072 1140  828 R  1.8  0.1   0:00.04 top                       
    1 root      20   0 21388 1556 1236 S  0.0  0.2   0:00.75 init                      
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                  
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0               
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.33 ksoftirqd/0               
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                 
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.04 watchdog/0   

=====================================

Terminal output from "stalled" agent task
=====================================

[root@centos62b ~]# zabbix_agentd -t local.php.test
local.php.test                               [cursor]

Other agentd tasks are periodically running

Comment by Jim Dutton [ 2017 Aug 06 ]

Hung agentd task finally times out
==================================

zabbix_agentd -t local.php.test
local.php.test                                [m|ZBX_NOTSUPPORTED] [Timeout while executing a shell script.]
Comment by Jim Dutton [ 2017 Aug 06 ]

Running the same script with the same version of Zabbix on the same client machine BUT
with a newer PHP (v5.6.32) - everything works just fine.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Aug 06 ]

Hm, if Zabbix times out, then everything on Zabbix side works as expected, doesn't it?

I would recommend to look for solution of PHP problem on our forum or IRC channel. Maybe it's even more PHP-related, then Zabbix-related. Or a weird selinux issue...

Closing as Won't Fix.

Comment by Jim Dutton [ 2017 Aug 07 ]

I have already established two resolutions: a) upgrade php to >= v5.4, b) run php UserParameter scripts under Apache (HTTPD), via "curl", using its php module to execute the PHP UserParameter script(s).

What would really be helpful for all is to update Zabbix Manual UserParameter sections to indicate the possibility of problems/issues if the PHP invoked by zabbix_agentd is version 5.3.3 and recommending installing PHP >= v5.4. This would allow other Zabbix implementers to make an informative decision about using PHP for Zabbix UserParameter scripts. It would also expand the scope of "external programs" possibly used with/by Zabbix.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Aug 07 ]

I'm not sure there is a suitable place in official Zabbix documentation (and the use case seems a bit too specific, we try to keep docs short and focused) but you are welcome to share your findings on zabbix.org

Generated at Sat Apr 27 02:17:47 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.