Skip to content
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 phalcon extension #16

Closed
Jeckerson opened this issue Nov 27, 2022 · 16 comments · Fixed by #17
Closed

Add phalcon extension #16

Jeckerson opened this issue Nov 27, 2022 · 16 comments · Fixed by #17
Assignees
Labels

Comments

@Jeckerson
Copy link

pecl install phalcon

Supported versions: 7.4, 8.0 and 8.1

@joseluisq
Copy link
Owner

Why not. BTW PR is welcome!

@joseluisq joseluisq added the help wanted Extra attention is needed label Nov 27, 2022
@joseluisq joseluisq self-assigned this Nov 30, 2022
@joseluisq joseluisq removed the help wanted Extra attention is needed label Nov 30, 2022
joseluisq added a commit that referenced this issue Nov 30, 2022
@niden
Copy link

niden commented Dec 1, 2022

Thank you @joseluisq

This will definitely help our development!

@joseluisq
Copy link
Owner

@niden awesome! Releases will come up soon.

@joseluisq
Copy link
Owner

joseluisq commented Dec 6, 2022

@niden @Jeckerson

when I try to build using the following

ARG PHALCON_VERSION="5.1.2"

RUN set -eux \
    && git clone --depth=1 --branch=v${PHALCON_VERSION} https://github.com/phalcon/cphalcon.git \
    && cd cphalcon/ext \
    && phpize && ./configure \
    && make -j$(nproc) \
    && make install \
    && docker-php-ext-enable phalcon \
    && true

Last lines of the build output:

re.o phalcon/.libs/14__closure.o phalcon/annotations/.libs/scanner.o phalcon/annotations/.libs/parser.o phalcon/mvc/model/.libs/orm.o phalcon/mvc/model/query/.libs/scanner.o phalcon/mvc/model/query/.libs/parser.o phalcon/mvc/view/engine/volt/.libs/parser.o phalcon/mvc/view/engine/volt/.libs/scanner.o phalcon/mvc/url/.libs/utils.o   -Wl,-soname -Wl,phalcon.so -o .libs/phalcon.so
creating phalcon.la
(cd .libs && rm -f phalcon.la && ln -s ../phalcon.la phalcon.la)
/bin/sh /var/www/html/cphalcon/ext/libtool --mode=install cp ./phalcon.la /var/www/html/cphalcon/ext/modules
cp ./.libs/phalcon.so /var/www/html/cphalcon/ext/modules/phalcon.so
cp ./.libs/phalcon.lai /var/www/html/cphalcon/ext/modules/phalcon.la
PATH="$PATH:/sbin" ldconfig -n /var/www/html/cphalcon/ext/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /var/www/html/cphalcon/ext/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

+ make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20200930/
Installing header files:          /usr/local/include/php/
+ cd ../../
+ rm -rf cphalcon
+ docker-php-ext-enable phalcon
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
(1/1) Installing .docker-php-ext-enable-deps (20221206.015428)
OK: 913 MiB in 269 packages
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.16/main: No such file or directory
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.16/community: No such file or directory
(1/1) Purging .docker-php-ext-enable-deps (20221206.015428)
OK: 913 MiB in 268 packages
+ true
Removing intermediate container 89a03be62f8c

When I try to use the container then I got this:

$ php -m

Warning: PHP Startup: Unable to load dynamic library 'phalcon' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20200930/phalcon (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20200930/phalcon: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20200930/phalcon.so (Error relocating /usr/local/lib/php/extensions/no-debug-non-zts-20200930/phalcon.so: backtrace: symbol not found)) in Unknown on line 0
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]

The PHP.ini is created at /usr/local/etc/php/conf.d/docker-php-ext-phalcon.ini using extension=phalcon
Definitely, I don't know why is failing so any help should be appreciated.

@joseluisq joseluisq reopened this Dec 6, 2022
@joseluisq
Copy link
Owner

The reason I would like to go with installing it in that way rather than the pecl install phalcon is that when using pecl I faced a "Virtual memory exhausted: Cannot allocate memory" error on CI.

pecl install phalcon is working in the native Docker build (x86_64) but when I use qemu for example it fails like this:

#8 4373.2  2018 | static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
#8 4373.2       |                                                                ~~~~~~~^~~~
#8 4373.2 virtual memory exhausted: Out of memory
#8 4373.2 make: *** [Makefile:209: phalcon.lo] Error 1
#8 4373.2 ERROR: `make' failed

https://github.com/joseluisq/alpine-php-fpm/actions/runs/3625455830/jobs/6113522781#step:7:16006

@Jeckerson
Copy link
Author

@joseluisq use build/ directory instead:

git clone https://github.com/phalcon/cphalcon.git
cd cphalcon/build
./install
docker-php-ext-enable phalcon

php --ri phalcon:

phalcon


Phalcon is a full stack PHP framework, delivered as a PHP extension, offering lower resource consumption and high performance.
phalcon => enabled
Author => Phalcon Team and contributors
Version => 5.1.2
Build Date => Dec  6 2022 09:09:01
Powered by Zephir => Version 0.16.3-5099f34

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.resultset_prefetch_records => 0 => 0
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.warning.enable => On => On

@joseluisq
Copy link
Owner

@Jeckerson great! I will give it a try with PHP 8.1

@joseluisq
Copy link
Owner

Released on v8.1.13

@joseluisq
Copy link
Owner

BTW I will also include phalcon in the next 8.0.27 release.

joseluisq added a commit that referenced this issue Dec 7, 2022
@joseluisq joseluisq added the v8.0 label Dec 7, 2022
@joseluisq
Copy link
Owner

Update: on PHP 8.0, phalcon is still failing with a "virtual memory exhausted: Out of memory" error via qemu.
https://github.com/joseluisq/alpine-php-fpm/actions/runs/3763057946/jobs/6396274244#step:6:35992

Any idea how to make it build?

@niden
Copy link

niden commented Dec 24, 2022

@Jeckerson might be able to shed some more light here but from what I recall (and looking at my old Stack overflow comment)

https://stackoverflow.com/questions/22819934/compiling-phalcon-virtual-memory-exhausted-cannot-allocate-memory

  • Add these flags to the make command
$CFLAGS --param ggc-min-expand=0 --param ggc-min-heapsize=8192

so that will make the script:

cd ext
phpize 
./configure --enable-phalcon CFLAGS="-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1 --param ggc-min-expand=0 --param ggc-min-heapsize=8192"
make -s
sudo make -s install
  • Second option is to install from the ext/ folder and not the build one. From what Andres wrote in our forum years ago, the build folder has one file that has the whole build recipe for all components. That is convenient but apparently uses more memory.
cd ext/
./install
  • Third is to increase the swap of the container at least for the build process. The article is for Ubuntu but I am sure there is something for Alpine also.

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

Notable is that I have the same issue with a bug report, where a member of the community sent me a repo with test code to reproduce a bug and the docker containers are in Alpine. I have several failures with it and was diagnosing it also :/

@Jeckerson
Copy link
Author

@niden Yes, it might help.

@joseluisq
Copy link
Owner

cd ext
phpize 
./configure --enable-phalcon CFLAGS="-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1 --param ggc-min-expand=0 --param ggc-min-heapsize=8192"
make -s
sudo make -s install

This first option is slower and consumes all the allowed time per running job (6h). So discarded.

  • Second option is to install from the ext/ folder and not the build one. From what Andres wrote in our forum years ago, the build folder has one file that has the whole build recipe for all components. That is convenient but apparently uses more memory.
cd ext/
./install

I did that #16 (comment) for 8.0 as well but it failed some time ago. But curious that It works for 8.1.

  • Third is to increase the swap of the container at least for the build process. The article is for Ubuntu but I am sure there is something for Alpine also.

I will investigate if I can address the problem in a similar way increasing swap space.

@joseluisq
Copy link
Owner

Minor update about Phalcon extension. Looks like you guys made possible to build the latest Phalcon 5.x for PHP 8.2.
It already passed the building process for the latest PHP 8.2.4 using Phalcon 5.2.1, so I will release it today as well as PHP 8.1.17 where it already is working.

@joseluisq
Copy link
Owner

But for PHP 8.0, it is still running out of memory on KVM ones with the latest Phalcon 5.2.1, which is weird because it is not the case for 8.1 or 8.2.

@Jeckerson
Copy link
Author

Might be due specific behaviour of PHP8.0 and our code base, as there are a lot of conditions to check PHP version.

@joseluisq joseluisq added v8.2 and removed v8.0 labels Mar 30, 2023
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 a pull request may close this issue.

3 participants