dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.87k stars 235 forks source link

suggestion about compile.md #601

Open rust17 opened 8 months ago

rust17 commented 8 months ago

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/toolchain@v0.0.1-go1.22.0.linux-amd64/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?

withinboredom commented 8 months ago

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).

rust17 commented 8 months ago

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.

withinboredom commented 8 months ago

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.

rust17 commented 8 months ago

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