swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.41k stars 3.16k forks source link

[FIXED] Undefined constant "SWOOLE_SOCK_TCP" (MAMP PRO) #5442

Closed IVoyt closed 3 weeks ago

IVoyt commented 1 month ago

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error. install swoole extension pecl install swoole with options
    • [ ] sockets
    • [x] openssl
    • [x] mysqlnd
    • [x] curl
    • [ ] cares
    • [x] brotli
    • [x] postgresql
    • [ ] odbc
    • [ ] oracle
    • [ ] sqlite

run php artisan octane:start

  1. What did you expect to see? started octane server

  2. What did you see instead? Uncaught Error: Class "Laravel\Octane\Octane" debugging led me to the error in the title

  3. What version of Swoole are you using (show your php --ri swoole)?

    
    swoole

Swoole => enabled Author => Swoole Team team@swoole.com Version => 5.1.3 Built => Aug 13 2024 15:05:59 coroutine => enabled with boost asm context kqueue => enabled rwlock => enabled openssl => OpenSSL 3.3.1 4 Jun 2024 dtls => enabled http2 => enabled json => enabled curl-native => enabled pcre => enabled zlib => 1.2.12 brotli => E16781312/D16781312 mysqlnd => enabled async_redis => enabled coroutine_pgsql => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_fiber_mock => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 262144 => 262144


5. What is your machine environment used (show your `uname -a` & `php -v` & `gcc -v`) ?

Darwin MacBook-Pro-Igor.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64

PHP 8.2.21 (cli) (built: Jul 22 2024 11:20:42) (NTS)

Apple clang version 15.0.0 (clang-1500.3.9.4)



`SWOOLE_SOCK_TCP6` is also undefined constant
NathanFreeman commented 1 month ago

Try to place the priority of Swoole at the end when loading the extension.

NathanFreeman commented 1 month ago

Try loading the Swoole extension at the end.

IVoyt commented 1 month ago

Try to place the priority of Swoole at the end when loading the extension.

you mean extensions order in php.ini? If so it did not help :(

NathanFreeman commented 1 month ago

Are you directly adding extension=swoole.so to the php.ini file? If so, try adding it to another configuration file, like this.

root@iZ7xv05bnlqyyku0ks7bzqZ:/home# php --ini
Configuration File (php.ini) Path: /etc/php/8.3/cli
Loaded Configuration File:         /etc/php/8.3/cli/php.ini
Scan for additional .ini files in: /etc/php/8.3/cli/conf.d
Additional .ini files parsed:      /etc/php/8.3/cli/conf.d/10-opcache.ini,
/etc/php/8.3/cli/conf.d/10-pdo.ini,
/etc/php/8.3/cli/conf.d/15-xml.ini,
/etc/php/8.3/cli/conf.d/20-calendar.ini,
/etc/php/8.3/cli/conf.d/20-ctype.ini,
/etc/php/8.3/cli/conf.d/20-curl.ini,
/etc/php/8.3/cli/conf.d/20-dom.ini,
/etc/php/8.3/cli/conf.d/20-exif.ini,
/etc/php/8.3/cli/conf.d/20-ffi.ini,
/etc/php/8.3/cli/conf.d/20-fileinfo.ini,
/etc/php/8.3/cli/conf.d/20-ftp.ini,
/etc/php/8.3/cli/conf.d/20-gettext.ini,
/etc/php/8.3/cli/conf.d/20-iconv.ini,
/etc/php/8.3/cli/conf.d/20-phar.ini,
/etc/php/8.3/cli/conf.d/20-posix.ini,
/etc/php/8.3/cli/conf.d/20-readline.ini,
/etc/php/8.3/cli/conf.d/20-shmop.ini,
/etc/php/8.3/cli/conf.d/20-simplexml.ini,
/etc/php/8.3/cli/conf.d/20-sockets.ini,
/etc/php/8.3/cli/conf.d/20-swoole.ini,
/etc/php/8.3/cli/conf.d/20-sysvmsg.ini,
/etc/php/8.3/cli/conf.d/20-sysvsem.ini,
/etc/php/8.3/cli/conf.d/20-sysvshm.ini,
/etc/php/8.3/cli/conf.d/20-tokenizer.ini,
/etc/php/8.3/cli/conf.d/20-xmlreader.ini,
/etc/php/8.3/cli/conf.d/20-xmlwriter.ini,
/etc/php/8.3/cli/conf.d/20-xsl.ini,
/etc/php/8.3/cli/conf.d/30-event.ini
IVoyt commented 1 month ago

I have only one php.ini. My setup is MAMP PRO 7 with manually built and added extension to /Applications/MAMP/bin/php/php8.2.21/conf/php.ini

NathanFreeman commented 1 month ago

It's possible that your computer has multiple PHP versions.

IVoyt commented 1 month ago

it looks like I have only one php version loaded at the moment

image

upd: I even checked if I have a brew version of php but nothing there

NathanFreeman commented 1 month ago
php -r "var_dump(SWOOLE_SOCK_TCP);"

Run this and check the output.

IVoyt commented 1 month ago
image

I assume this means the constant is visible to the interpreter. This is weird. Then why laravel octane is falling with exception!?

NathanFreeman commented 1 month ago

php -m to see the list of extensions.

IVoyt commented 1 month ago
❯ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
imap
intl
json
ldap
libxml
mbstring
memcached
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
random
readline
redis
Reflection
session
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
swoole
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
IVoyt commented 1 month ago

phpinfo also displays that module is loaded

image
NathanFreeman commented 1 month ago

Have you execute the octane:install Artisan command?

IVoyt commented 1 month ago

Of course I did

image
NathanFreeman commented 1 month ago

Can you show me the full error message?

NathanFreeman commented 1 month ago

It looks like Octane has been successfully started here, and this error seems to have occurred after the startup.

IVoyt commented 1 month ago
Снимок экрана 2024-08-13 в 17 10 18

I'm throwing this exception explicitly

image

because by default the error is Fatal error: Uncaught Error: Class "Laravel\Octane\Octane" not found in /Users/<projectPath>/vendor/laravel/octane/src/Stream.php:56 which is unclear

NathanFreeman commented 1 month ago

Can you directly access http://127.0.0.1:8000? If there is output, then Octane has been successfully started, and the issue is caused elsewhere.

IVoyt commented 1 month ago

No, I can't. It fails immediately after the start.

The weird thing is that the constant is available everywhere except one particular file vendor/laravel/octane/bin/createSwooleServer.php

Maybe I need to ask help at Laravel maintainers. Thanks for your help!

I'll write back if I'll have any updates on this issue

jingjingxyk commented 1 month ago

php --ini Command execution output ?

IVoyt commented 1 month ago

php --ini Command execution output ?

image
jingjingxyk commented 1 month ago

Block interference from the system environment

try static build php : https://github.com/swoole/build-static-php/releases/download/v1.3.2/php-cli-v8.2.13-macos-arm64.tar.xz

https://github.com/swoole/build-static-php/releases/tag/v1.3.2


curl -fSL https://github.com/swoole/build-static-php/blob/main/setup-php-cli-runtime.sh?raw=true | bash

Please provide the execution output result ?

IVoyt commented 1 month ago

the static build shows that ini is located in /usr/local/lib, but there is nothing related to php

image

upd: maybe you meant to reproduce problem with undefined constant? Yep, with static build it seems to work

jingjingxyk commented 1 month ago

the static build shows that ini is located in /usr/local/lib, but there is nothing related to php

image

export PATH=/your-workpath/php-cli-v8.2.13/bin/runtime/:$PATH alias php='php -c /your-workpath/php-cli-v8.2.13/bin/runtime/php.ini' php -v php --ri swoole

php artisan octane:install php artisan octane:start --works=4

jingjingxyk commented 1 month ago

https://wiki.swoole.com/zh-cn/#/environment?id=pecl

IVoyt commented 1 month ago

the static build shows that ini is located in /usr/local/lib, but there is nothing related to php

image

export PATH=/your-workpath/php-cli-v8.2.13/bin/runtime/:$PATH alias php='php -c /your-workpath/php-cli-v8.2.13/bin/runtime/php.ini' php -v php --ri swoole

php artisan octane:install php artisan octane:start --works=4

thanks, I already tested and it works.

But can you give me an advice how to fix this on my setup not using static build. Because I already have compiled extension with pecl by instructions from the documentation

jingjingxyk commented 1 month ago

Missing sockets extensions and c-ares library

brew install c-ares

and

reinstall swoole


pecl install --configureoptions 'enable-sockets="yes" enable-openssl="yes" enable-mysqlnd="yes"  enable-swoole-curl="yes" enable-cares="yes"'  swoole
IVoyt commented 1 month ago

I've installed brew install c-ares and recompiled the extension with command you provided but unfortunately it does not help

jingjingxyk commented 1 month ago

I've installed brew install c-ares and recompiled the extension with command you provided but unfortunately it does not help

enable extension sockets?

IVoyt commented 1 month ago

yes, I used exact command you provided

matyhtf commented 3 weeks ago

Undefined constant "SWOOLE_SOCK_TCP"

This is because the swoole extension has not been loaded

Uncaught Error: Class "Laravel\Octane\Octane"

Check if you have executed composer install laravel/octane

IVoyt commented 3 weeks ago

Undefined constant "SWOOLE_SOCK_TCP"

This is because the swoole extension has not been loaded

Uncaught Error: Class "Laravel\Octane\Octane"

Check if you have executed composer install laravel/octane

thank you for your contribution to solving the problem

Did you read carefully all this thread? If you did, you should notice that I executed composer install laravel/octane and that the extension was loaded when the laravel is initiated. But when the control of execution is transfered to the Octane package the Swoole constants become inaccessible for php

IVoyt commented 3 weeks ago

I've found the problem. Thank you @NathanFreeman & @jingjingxyk for pointing me to the direction of the solution.

The problem was in MAMP PRO. When installed it creates another ini file located at /Library/Application Support/appsolute/MAMP PRO/conf/ where it writes own directives (let's call it "custom"). I was adding the swoole extension into the custom ini.

So there are 2 ini files in the system. And changing custom ini does not mirror changes on default ini. And that was the problem since when control of execution was transferred to the Octane package, there was probably created some sub process of php which for some reason uses default ini, in which the extension was missing. So the solution was to specify extension in the default ini.