a php http request extension on concurrence writing in golang
use FFI to call golang http requests with concurrence.
install
- add follow contents to project's composer.json and run
composer install && composer run-script downloadExtension.
{
"require": {
"fthvgb1/gophpfetch": "*"
},
"scripts": {
"downloadExtension": [
"@putenv COMPOSER=vendor/fthvgb1/gophpfetch/composer.json",
"@composer downloadExtension"
]
}
}
to avoid including the unnecessary others platform's extension files, you need to download extension file manually
in release.
- enable ffi extension add follow config to php.ini or ffi.ini to using in php-fpm
extension=ffi.so
ffi.enable=true
example
$results = Fetch::fetch([
[
'url' => 'url',
'method' => 'get',//default
'id' => 'get request',
'query' => ['query param' => 'values']
],
[
'url' => 'url',
'id' => 'post request',
'body' => ['post body param' => 'values'],
'header' => [
'Content-Type' => PostType::FormUrlencoded, //default post type
]
],
[
'url' => 'download url',
'method' => 'get',
'query' => ['query param' => 'value'],
'id' => 'dowload file',
'saveFile' => [
'path' => 'save path',
'mode' => '0644', //default
'dirMode '=> '0755' //default
]
],
[
'url' => 'upload url',
'method' => 'post',
'id' => 'upload file',
'header' => ['Content-Type' => PostType::FormData],
'body' => [
'__uploadFiles' => [
'local file' => 'field'
]
]
]
]);
upload 5 files and download 5 files in a request on concurrence
results:






|
gophpfetch |
multiple curl |
swoole curl |
| xdebug |
|
| xhprof |
test method and scripts see here
reference
dwdcth/php_golang_ffi