frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

suggestion about compile.md

Open rust17 opened this issue 1 year ago • 4 comments

Describe you feature request

Is your feature request related to a problem? Please describe. When I have multiple versions of PHP installed (php7.4, php8.1, php8.3), I execute the run command:

CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) $(php-config --libs)" go run .

It prompts:

# github.com/dunglas/frankenphp/caddy/frankenphp
/home/circle/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lphp
collect2: error: ld returned 1 exit status

Describe the solution you'd like This error indicates that the ld encountered a problem when trying to link the libphp library. After I changed it to this, the program can run:

CGO_CFLAGS=$(php-config --includes) CGO_LDFLAGS="$(php-config --ldflags) -L/usr/local/php8.3/lib -lphp $(php-config --libs)" go run . run

Should this be written into compile.md?

rust17 avatar Feb 26 '24 14:02 rust17

While FrankenPHP will run with non-thread-safe builds of php, I suspect it will act in surprising ways. I assume that is what you mean by "multiple versions of php installed"?

FrankenPHP uses threads instead of a process model and should be built against a thread-safe version of php or it might result in memory corruption and/or sharing data between threads that shouldn't be shared (like session data).

withinboredom avatar Feb 26 '24 17:02 withinboredom

While FrankenPHP will run with non-thread-safe builds of php, I suspect it will act in surprising ways. I assume that is what you mean by "multiple versions of php installed"?

FrankenPHP uses threads instead of a process model and should be built against a thread-safe version of php or it might result in memory corruption and/or sharing data between threads that shouldn't be shared (like session data).

I believe the issue might be connected to the method I used to install PHP. I installed multiple versions of php, each with a specified prefix. For instance, PHP 8.3 was installed with the prefix --prefix=/usr/local/php8.3, and PHP 8.1 with --prefix=/usr/local/php8.1. According to the php-src sapi documentation, the command php-config --libs doesn't return lphp, so the linker uncertain about which library to link to:

$ php-config --libs

outputs:

-lresolv -lrt -lutil -lrt -lm -ldl -lpthread -lxml2 -lssl -lcrypto -lsqlite3 -lz -lcurl -lxml2 -lz -lpng16 -lz -lwebp -ljpeg -lfreetype -lonig -lsqlite3 -lxml2 -lxml2 -lxml2 -lxml2 -lzip -lz -lssl -lcrypto

This might be the root cause of the problem.

rust17 avatar Feb 27 '24 02:02 rust17

php-config is also unprefixed, so it points to the last version of php you installed (IIRC). I'm not near a computer today to verify that, but I've run into a similar issue at some point.

withinboredom avatar Feb 27 '24 07:02 withinboredom

Sorry, forget about the context earlier. I use source ./profile to set the php version, the php-config corresponds to the same version as the php itself. By the way, this is not urgent, no need for a rush response. image

image image

rust17 avatar Feb 27 '24 08:02 rust17