arnaud-lb / php-go

php-go allows to call Go code from PHP, with minimal code boilerplate
MIT License
187 stars 20 forks source link

loading extension twice results in an error #2

Open jrots opened 6 years ago

jrots commented 6 years ago

Hi, When you run :

$module = phpgo_load("/path/to/example.so", "example");
$module = phpgo_load("/path/to/example.so", "example");

$module->toUpper("foo");

twice and try to call a function you'll get an error :

Uncaught Error: Call to undefined method PHPGo\Module\�Ә�_1_426c601a::toUpper.. 

initializing it once will work ..

I have PHP running "fpm" context so it can happen that a worker gets reused and thus calls phpgo_load again. Haven't looked to it in detail but think it's something with the cache key of the loaded module in the php extension that goes wrong.

jrots commented 6 years ago

forgot to mention, running: php -v PHP 7.1.8

jrots commented 6 years ago

Kind of dirty fixed it to make it work with only one module for me, i'm not an expert C guy -) (https://github.com/jrots/php-go/commit/29fc862ed79db032d40d53d7d09c5a4b9eba05ae) by disabling the hashmap cache (only keeping a static reference on top in the module).. so must be something that's changed in the way hashmaps are handled in php 7.1.x

EricKim65 commented 4 years ago

Thank you for writing a nice code for php-go user, arnaud ! I am very appreciated this result but

I have a similar error during testing it:

1) It is good to run phpgo_load at first time in web page [Output in page] Class [ final class PHPGo\Module\example_0_107063be ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [2] { Method [ public method takeOverTheWorld ] { - Parameters [0] { } } Method [ public method toUpper ] { - Parameters [1] { Parameter #0 [ $string_0 ] } } } }

2) Refresh page second time ( in a few second after first run ) Class [ final class PHPGo\Module_2_39b3e97f ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [0] { } } Fatal error: Uncaught Error: Call to undefined method PHPGo\Module_2_39b3e97f::toUpper() in /home/webhost/webhost.dabory.com/phpinfo.php:9 Stack trace: #0 {main} thrown in /home/webhost/webhost.dabory.com/phpinfo.php on line 9 ==> the module name looks broken and cannot be found.

3) A few minute late, Refreshing the page, I run without error just like 1)

4) The module looks like associated with garbage collection or cleaning memory issue.

Test environment : 1) linux CentOS 7.5 64bit 2) Apache 2.4 3) PHP 7.3

May I get helped about this, Arnaud ? I am very desparate to implement this functionality. I can pay money for spending your time if you want to.

banfg56 commented 4 years ago

PHP 7.4 support FFI feature , see here @EricKim65