承接 vulcanphp/easycurl 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vulcanphp/easycurl

最新稳定版本:v1.0.0

Composer 安装命令:

composer require vulcanphp/easycurl

包简介

Easy Curl is a helper class for PHP that make the HTTP requests easier

README 文档

README

Easy Curl is a helper class for PHP that make the HTTP requests easier

Installation

It's recommended that you use Composer to install PHP Easy Curl

$ composer require vulcanphp/easycurl

PHP Easy Curl Basic Usage

<?php
// index.php

use VulcanPhp\EasyCurl\EasyCurl;

require_once __DIR__ . '/vendor/autoload.php';

// make a http get, post, put, patch, and delete request
var_dump(
    EasyCurl::get('https://jsonplaceholder.typicode.com/posts')
        ->getJson()
);

// can make every http request statically
var_dump(
    EasyCurl::put('https://jsonplaceholder.typicode.com/posts/1')
        ->getBody()
);

// create a Easy Curl instance
$http = EasyCurl::create();

// set curl options
$http->setOption(CURLOPT_TIMEOUT, 20);

// set header
$http->setHeader('Authorization', 'Bearer {token}');

// set postfields 
$http->setPostFields(['name' => 'John Doe', 'email' => 'john@mail.com']);

// send this request
$resp = $http->post('http://your-location.domain/path');

// print the response
var_dump($resp);

// ...

Usage of PHP Easy Curl Response

<?php
// index.php
use VulcanPhp\EasyCurl\EasyCurl;

require_once __DIR__ . '/vendor/autoload.php';

$resp = EasyCurl::get('https://jsonplaceholder.typicode.com/posts');

// get the curl output in array
var_dump($resp->getResponse());

// get the curl status
var_dump($resp->getStatus());

// get response body
var_dump($resp->getBody());

// if the output is json format we can convert it with array
var_dump($resp->getJson()); 

// get output content length
var_dump($resp->getLength());

// get curl last effective url
var_dump($resp->getLastUrl());

// Tip: all methods can be called without get word, EX: $resp->body() is equal to $resp->getBody()

Quick Usage

<?php
// index.php

use VulcanPhp\EasyCurl\EasyCurl;

require_once __DIR__ . '/vendor/autoload.php';

// quick create a curl instance with static/non-static methods
$http = EasyCurl::options([
    CURLOPT_TIMEOUT => 20,
    // all curl_setopt() options 
]);

// send method is equal to get method, or you can use any http methods
$resp = $http->send('http://domain.com/path');

// download a file
$status = EasyCurl::downloadFile(__DIR__ . '/test.txt')
    ->get('http://domain.com/path')
    ->status();

var_dump($status);

// setup a proxy in easy curl
$http = EasyCurl::proxy([
    'ip'    => '127.0.0.1', // proxy ip
    'port'  => '8080', // proxy port
    'auth'  => 'user:pass', // basic proxy auth
]);

var_dump($http->get('http://domain.com/path'));

// ...

Available Methods to EasyCurl Driver

  • send(string $url, array $params = []): ICurlResponse
  • get(string $url, array $params = []): ICurlResponse
  • post(string $url, array $params = []): ICurlResponse
  • put(string $url, array $params = []): ICurlResponse
  • patch(string $url, array $params = []): ICurlResponse
  • delete(string $url, array $params = []): ICurlResponse
  • setOption(int $key, mixed $value): ICurlDriver
  • setOptions(array $options): ICurlDriver
  • setUseragent(string $useragent): ICurlDriver
  • setHeader(string $key, string $value): ICurlDriver
  • setHeaders(array $headers): ICurlDriver
  • setCookieFile(string $filepath): ICurlDriver
  • setDownloadFile(string $filepath, bool $override = false): ICurlDriver
  • setPostFields(mixed $fields): ICurlDriver
  • setProxy(array $proxy): ICurlDriver

Note: You can call these every methods statically when creating a Easy Curl Instance.

and you can also call every set methods without (set) word, EX: EasyCurl::option() is equal to EasyCurl::setOption()

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-26