SlideShare a Scribd company logo
10
Most read
14
Most read
15
Most read
2015/11/24 PHP BLT
do_aki
Writing
php extensions
in golang
@do_aki
@do_aki
http://do-aki.net/
Writing php extensions in golang
https://speakerdeck.com/naruse/writing-extension-libraries-in-go
In case of PHP……?
golang buildmode
• -buildmode=c-shared
• build the main package (main
function is dummy)
• export symbol by “//export”
https://golang.org/s/execmodes
cgo(call C function)
package main
/*
#include <stdlib.h>
*/
import “C”
func Random() int {
return int(C.random())
}
cgo(export)
package main
import “C”
//export go_func
func go_func() int {
return 1
}
php extension loading process
1. load shared library (.so / .dll)
2. fetch “get_module” or
“_get_module” symbol
3. call fetched function and get
pointer to zend_module_entry
structure
4. register module using the
zend_module_entry
ref:php_load_extension in ext/standard/dl.c
export get_module
package main
/*
#include “php.h”
*/
import “C”
var gophp_module_entry C.zend_module_entry
//export get_module
func get_module() *C.zend_module_entry {
gophp_module_entry.name = C.Cstring(“gophp”)
gophp_module_entry.functions = …
// fill member in gophp_module_entry
return gophp_module_entry;
}
export get_module
package main
/*
#include “php.h”
*/
import “C”
var gophp_module_entry C.zend_module_entry
//export get_module
func get_module() *C.zend_module_entry {
gophp_module_entry.name = C.Cstring(“gophp”)
gophp_module_entry.functions = …
// fill member in gophp_module_entry
return gophp_module_entry;
}
constraints of c in go
function
-like
macro
Access
union
member
separate export function and
function definition
• err: multiple definition of ` xxx'
• write definition in non_export.go
(not include //export)
• write declarations in export.go
(include //export)
• go build non_export.go export.go
github.com/do-aki/gophp_sample
but,but,but
• segmentation fault in shutdown
process sometimes……
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffee4c2700 (LWP 8943)]
0x00007ffff04d6821 in ?? ()
(gdb) backtrace
#0 0x00007ffff04d6821 in ?? ()
#1 0x00007ffff04a6213 in ?? ()
#2 0x000000c82002ce90 in ?? ()
#3 0x0000000000000000 in ?? ()
in go runtime? Umm…
fin.

More Related Content

What's hot (20)

PDF
webpack 101 slides
mattysmith
 
PPTX
Web Components and Security
Tyler Peterson
 
PPTX
Introduction à React
Abdoulaye Dieng
 
PDF
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
PDF
Unsafe JAX-RS: Breaking REST API
Mikhail Egorov
 
PDF
Express node js
Yashprit Singh
 
PPTX
Introduction à React JS
Abdoulaye Dieng
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PDF
Spring security oauth2
axykim00
 
PPTX
Node js introduction
Joseph de Castelnau
 
PPTX
Initiation à Express js
Abdoulaye Dieng
 
PPTX
Hadoop et son écosystème
Khanh Maudoux
 
PDF
MongoDB Sharding Fundamentals
Antonios Giannopoulos
 
PDF
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Julian Hyde
 
PDF
Tutoriel J2EE
Dghaies Jihed , PSM I Ⓡ
 
PDF
Spring Boot
koppenolski
 
PDF
Spring boot
Bhagwat Kumar
 
PPTX
Building Next-Generation Web APIs with JSON-LD and Hydra
Markus Lanthaler
 
PPTX
Spring Framework
tola99
 
webpack 101 slides
mattysmith
 
Web Components and Security
Tyler Peterson
 
Introduction à React
Abdoulaye Dieng
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!
 
Unsafe JAX-RS: Breaking REST API
Mikhail Egorov
 
Express node js
Yashprit Singh
 
Introduction à React JS
Abdoulaye Dieng
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
Spring security oauth2
axykim00
 
Node js introduction
Joseph de Castelnau
 
Initiation à Express js
Abdoulaye Dieng
 
Hadoop et son écosystème
Khanh Maudoux
 
MongoDB Sharding Fundamentals
Antonios Giannopoulos
 
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Julian Hyde
 
Spring Boot
koppenolski
 
Spring boot
Bhagwat Kumar
 
Building Next-Generation Web APIs with JSON-LD and Hydra
Markus Lanthaler
 
Spring Framework
tola99
 

Viewers also liked (20)

PPTX
php7's ast
do_aki
 
PPTX
N対1 レプリケーション + Optimizer Hint
do_aki
 
PPTX
PHP AST 徹底解説(補遺)
do_aki
 
PPTX
signal の話 或いは Zend Signals とは何か
do_aki
 
PPTX
PHP AST 徹底解説
do_aki
 
PDF
Current status of PSR - Phpblt1
Yui Sakamoto
 
ODP
Go nuts with Go and PHP
Mariano Iglesias
 
PPTX
20141011 mastering mysqlnd
do_aki
 
PPTX
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
do_aki
 
PPTX
Writing and using php streams and sockets
Elizabeth Smith
 
PDF
php-buildがいかに便利かを力説する
Yoshio Hanawa
 
PPTX
Excel is image viewer
do_aki
 
PDF
Dependency Injection and Pimple
DQNEO
 
PDF
Phpでアプリケーションサーバー
k-motoyan
 
PPTX
Socket programming with php
Elizabeth Smith
 
PDF
たのしい独自フレームワーク
Kenta USAMI
 
PDF
Big Master Data PHP BLT #1
Masahiro Nagano
 
PDF
Time series with Apache Cassandra - Long version
Patrick McFadin
 
PPTX
Technical Introduction to IBM's Open Blockchain (OBC)
Altoros
 
PPTX
Anatomy of a hyperledger application
Eric Cattoir
 
php7's ast
do_aki
 
N対1 レプリケーション + Optimizer Hint
do_aki
 
PHP AST 徹底解説(補遺)
do_aki
 
signal の話 或いは Zend Signals とは何か
do_aki
 
PHP AST 徹底解説
do_aki
 
Current status of PSR - Phpblt1
Yui Sakamoto
 
Go nuts with Go and PHP
Mariano Iglesias
 
20141011 mastering mysqlnd
do_aki
 
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
do_aki
 
Writing and using php streams and sockets
Elizabeth Smith
 
php-buildがいかに便利かを力説する
Yoshio Hanawa
 
Excel is image viewer
do_aki
 
Dependency Injection and Pimple
DQNEO
 
Phpでアプリケーションサーバー
k-motoyan
 
Socket programming with php
Elizabeth Smith
 
たのしい独自フレームワーク
Kenta USAMI
 
Big Master Data PHP BLT #1
Masahiro Nagano
 
Time series with Apache Cassandra - Long version
Patrick McFadin
 
Technical Introduction to IBM's Open Blockchain (OBC)
Altoros
 
Anatomy of a hyperledger application
Eric Cattoir
 
Ad

More from do_aki (20)

PPTX
Tritonn から Elasticsearch への移行話
do_aki
 
PPTX
php-src の歩き方
do_aki
 
PPTX
PHP と SAPI と ZendEngine3 と
do_aki
 
PPTX
PHPとシグナル、その裏側
do_aki
 
PPTX
再考:列挙型
do_aki
 
PPTX
20150212 プレゼンテーションzen
do_aki
 
PPTX
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
do_aki
 
PPTX
20141017 introduce razor
do_aki
 
PPTX
php in ruby
do_aki
 
PPTX
PHP から Groonga を使うにはこんなコードになるよ!
do_aki
 
PPTX
N:1 Replication meets MHA
do_aki
 
PDF
Php radomize
do_aki
 
PPTX
php and sapi and zendengine2 and...
do_aki
 
PPTX
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
do_aki
 
PPTX
Immortal
do_aki
 
PDF
A bridge between php and ruby
do_aki
 
PDF
Ruby and comparison_and...php
do_aki
 
PPTX
Sore php
do_aki
 
PPTX
Php in ruby
do_aki
 
PPTX
Ruby enumerable source code reading
do_aki
 
Tritonn から Elasticsearch への移行話
do_aki
 
php-src の歩き方
do_aki
 
PHP と SAPI と ZendEngine3 と
do_aki
 
PHPとシグナル、その裏側
do_aki
 
再考:列挙型
do_aki
 
20150212 プレゼンテーションzen
do_aki
 
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
do_aki
 
20141017 introduce razor
do_aki
 
php in ruby
do_aki
 
PHP から Groonga を使うにはこんなコードになるよ!
do_aki
 
N:1 Replication meets MHA
do_aki
 
Php radomize
do_aki
 
php and sapi and zendengine2 and...
do_aki
 
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
do_aki
 
Immortal
do_aki
 
A bridge between php and ruby
do_aki
 
Ruby and comparison_and...php
do_aki
 
Sore php
do_aki
 
Php in ruby
do_aki
 
Ruby enumerable source code reading
do_aki
 
Ad

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PPTX
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Simplify Your FME Flow Setup: Fault-Tolerant Deployment Made Easy with Packer...
Safe Software
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 

Writing php extensions in golang