Open beeradmoore opened 1 year ago
I created a Dockerfile which has a repo of this issue.
FROM amazonlinux:2.0.20230320.0
WORKDIR /meminfo/
# Update, install required tools
RUN yum update -y && \
amazon-linux-extras install -y php8.0 && \
yum install -y php-devel gcc make unzip
# Download and extract php-meminfo
RUN curl -L -o /meminfo/master.zip https://github.com/BitOne/php-meminfo/archive/refs/heads/master.zip
RUN unzip /meminfo/master.zip
# Install meminfo
RUN cd /meminfo/php-meminfo-master/extension && \
phpize && \
./configure --enable-meminfo && \
make && \
make install && \
echo "extension=meminfo.so" >> /etc/php.ini
COPY test.php /meminfo/test.php
CMD ["php", "/meminfo/test.php"]
Where test.php is
<?php
$some_bool = false;
if ($some_bool === true)
{
$test = new stdClass();
}
meminfo_dump(fopen('/tmp/my_dump_file.json', 'w'));
echo time();
Can be built with
docker build -t php-meminfo .
Can be ran with
docker run --rm php-meminfo:latest If you see the time output then it worked, if no time is output it failed.
You can dig deeper into it by running (at least on macOS, for other OS you may need to change $PWD)
docker run -v $PWD/test.php:/meminfo/test.php --rm -it php-meminfo:latest /bin/sh
By modifying the php version installed I was able to confirm this test fails on php8.0 was able to confirm the test fails with the following php versions
PHP 8.0.28 (cli) (built: Mar 28 2023 17:41:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
PHP 8.1.16 (cli) (built: Mar 23 2023 19:44:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.16, Copyright (c) Zend Technologies
PHP 8.2.3 (cli) (built: Mar 15 2023 21:12:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
Modifying docker image from the php-meminfo-1.1.1
release I can test on php5 and can confirm it works.
PHP 5.4.16 (cli) (built: Oct 31 2019 18:34:05)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
This is the php5 Dockerfile for testing.
FROM amazonlinux:2.0.20230320.0
WORKDIR /meminfo/
# Update, install required tools
RUN yum update -y && \
yum install -y php php-devel gcc make unzip
# Download and extract php-meminfo
RUN curl -L -o /meminfo/v1.1.1.zip https://github.com/BitOne/php-meminfo/archive/refs/tags/v1.1.1.zip
RUN unzip /meminfo/v1.1.1.zip
# Install meminfo
RUN cd /meminfo/php-meminfo-1.1.1/extension/php5/ && \
phpize && \
./configure --enable-meminfo && \
make && \
make install && \
echo "extension=meminfo.so" >> /etc/php.ini
COPY test.php /meminfo/test.php
CMD ["php", "/meminfo/test.php"]
For some reason there is no php7.4 to test with 🤷♂️
EDIT: Building from php docker image base I was able to get the test to pass with php7.4
FROM php:7.4-fpm
WORKDIR /meminfo/
# Update, install required tools
RUN apt update && apt upgrade -y && \
apt install unzip -y
# Download and extract php-meminfo
RUN curl -L -o /meminfo/master.zip https://github.com/BitOne/php-meminfo/archive/refs/heads/master.zip
RUN unzip /meminfo/master.zip
# Install meminfo
RUN cd /meminfo/php-meminfo-master/extension && \
phpize && \
./configure --enable-meminfo && \
make && \
make install && \
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
echo "extension=meminfo.so" >> /usr/local/etc/php/php.ini
COPY test.php /meminfo/test.php
CMD ["php", "/meminfo/test.php"]
Updating to php8.2 to build from the test also passes. Which means there is something wrong/missing with the php from AWS.
I have the same problem, I'll try to fix it
Program received signal SIGSEGV, Segmentation fault
0x00007ffff2b43fb6 in meminfo_browse_class_static_members (stream=stream@entry=0x7ffff54c2ee0, visited_items=visited_items@entry=0x7fffed5f8cf0, first_element=first_element@entry=0x7fffed5f8ce4)
at /opt/progs/php-meminfo/extension/meminfo.c:147
147 if (class_entry->default_static_members_count > 0 && CE_STATIC_MEMBERS(class_entry)) {
(gdb) bt
#0 0x00007ffff2b43fb6 in meminfo_browse_class_static_members (stream=stream@entry=0x7ffff54c2ee0, visited_items=visited_items@entry=0x7fffed5f8cf0, first_element=first_element@entry=0x7fffed5f8ce4)
at /opt/progs/php-meminfo/extension/meminfo.c:147
#1 0x00007ffff2b445be in zif_meminfo_dump (execute_data=<optimized out>, return_value=<optimized out>) at /opt/progs/php-meminfo/extension/meminfo.c:80
#2 0x00005555558a5d48 in execute_ex ()
#3 0x000055555582dcbc in zend_call_function ()
#4 0x00005555558d72c9 in ?? ()
#5 0x00005555558d82b2 in ?? ()
#6 0x00005555557d6287 in make_fcontext ()
#7 0x0000000000000000 in ?? ()
Добрый день.
Буду находиться в отпуске с 5.02 по 13.02. Настроена пересылка писем Татьяне Кубаревой @.***, если вопрос срочный, она ответит Вам. На менее срочные письма я отвечу после возвращения.
TL;DR; Weird thing happens with php8+ when using Amazon Linux 2. Using docker images from php for php8+ the same test pasts. Issue appears to be related to the specific packages installed not php as a whole. BUT it does also show some odd things happening by moving code about.
I'm not sure how to debug php-meminfo itself, but I have a really odd one that I was able to replicate down to a small test. The test consists of
TestClass
in which I want to use the staticCurrent()
method to get a single instance of the class.This will result in SIGSEGV which will result in apache giving a 503 response. But things get really odd really quick.
If you change
to
then the code will work. Maybe something about having a reference to the variable? But it's odd because the code will never execute as
$some_bool
is false.Another oddity is if you move the declaration outside of the if then it will also work as expected.
EDIT: I also just found it has nothing to do with the static variable. The new minimum test case is
I should have also included specs. This is running on a Amazon Linux 2 EC2 instance. php version is
As for php-meminfo, I built it from the current master source.
EDIT 2:
This can be replicated without the TestClass
EDIT 3: Looks like maybe it has something to do with code being removed when executed or something.
This works
This does not
But in saying that this works and it shouldn't according to the above example
But then this also works
You can also get this to fail with primatives.