gophpfetch

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 5 Imported by: 0

README

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'
            ]
        ]
    ]
]);

performance comparison

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL