Skip to content

Commit 0f16123

Browse files
committed
added readme
1 parent 4a409e8 commit 0f16123

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.so
22
*.h
3+
.buildpath
4+
.project
5+
.settings/

ackermann.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Combining PHP and Go gives a lot of new opportunities.
3333
*
3434
* 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.
3636
*/
3737

3838
error_reporting(E_ALL);

readme.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.

0 commit comments

Comments
 (0)