File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
1
* .so
2
2
* .h
3
+ .buildpath
4
+ .project
5
+ .settings /
Original file line number Diff line number Diff line change 32
32
* Combining PHP and Go gives a lot of new opportunities.
33
33
*
34
34
* Writing and integrating PHP extensions based on C/C++ can be difficult and time consuming.
35
- * This can be made easier and more flexible using Go and PHP-FFI.
35
+ * This can be made easier and more flexible using Go libraries and PHP-FFI.
36
36
*/
37
37
38
38
error_reporting (E_ALL );
Original file line number Diff line number Diff line change
1
+ PHP Example to integrate Go using PHP-FFI
2
+ ------------------------------------------
3
+
4
+ Go is a statically typed, compiled programming language that offers more performance and concurrency.
5
+ Combining PHP and Go gives a lot of new opportunities.
6
+
7
+ Writing and integrating PHP extensions based on C/C++ can be difficult and time consuming.
8
+ This can be made easier and more flexible using Go libraries and PHP-FFI.
9
+
10
+ Go code can compiled as a shared object file (.so) and loaded in PHP using PHP-FFI.
11
+ (see https://www.php.net/manual/en/book.ffi.php )
12
+
13
+ This example compares the performance of PHP and Go using implementations
14
+ of the recursive ackermann function (see https://en.wikipedia.org/wiki/Ackermann_function ).
15
+ In this example Go 1.14 is 27 times faster than PHP 7.4.
16
+
17
+ Usage:
18
+
19
+ go build -o ackermann.so -buildmode=c-shared ackermann.go
20
+
21
+ php ackermann.php
22
+
23
+ Requirements:
24
+
25
+ Go package (https://golang.org/dl/)
26
+
27
+ PHP 7.4+
28
+
29
+ Notes:
30
+
31
+ PHP-FFI can automatically convert basic Go types (long, char* ) into PHP types.
32
+ For using more complex data structures, I'm also providing an example (ackermann_json)
33
+ using JSON strings as input and output.
You can’t perform that action at this time.
0 commit comments