Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions examples/multi_curl_add_curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@
});

$curl_1 = new Curl();
$curl_1->setOpt(CURLOPT_POST, true);
$curl_1->setOpt(CURLOPT_POSTFIELDS, [
$curl_1->setPost('https://httpbin.org/post', [
'to' => 'alice',
'subject' => 'hi',
'body' => 'hi Alice',
]);
$curl_1->setUrl('https://httpbin.org/post');
$multi_curl->addCurl($curl_1);

$curl_2 = new Curl();
$curl_2->setOpt(CURLOPT_POST, true);
$curl_2->setOpt(CURLOPT_POSTFIELDS, [
$curl_2->setPost('https://httpbin.org/post', [
'to' => 'bob',
'subject' => 'hi',
'body' => 'hi Bob',
]);
$curl_2->setUrl('https://httpbin.org/post');
$multi_curl->addCurl($curl_2);

$multi_curl->start();
33 changes: 33 additions & 0 deletions examples/multi_curl_add_curl_low_level.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

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

use Curl\Curl;
use Curl\MultiCurl;

$multi_curl = new MultiCurl();
$multi_curl->complete(function ($instance) {
echo 'call to "' . $instance->url . '" completed.' . "\n";
});

$curl_1 = new Curl();
$curl_1->setOpt(CURLOPT_POST, true);
$curl_1->setOpt(CURLOPT_POSTFIELDS, [
'to' => 'alice',
'subject' => 'hi',
'body' => 'hi Alice',
]);
$curl_1->setUrl('https://httpbin.org/post');
$multi_curl->addCurl($curl_1);

$curl_2 = new Curl();
$curl_2->setOpt(CURLOPT_POST, true);
$curl_2->setOpt(CURLOPT_POSTFIELDS, [
'to' => 'bob',
'subject' => 'hi',
'body' => 'hi Bob',
]);
$curl_2->setUrl('https://httpbin.org/post');
$multi_curl->addCurl($curl_2);

$multi_curl->start();
56 changes: 48 additions & 8 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ private function progressInternal($callback)
* @return mixed Returns the value provided by exec.
*/
public function delete($url, $query_parameters = [], $data = [])
{
$this->setDelete($url, $query_parameters, $data);
return $this->exec();
}

public function setDelete($url, $query_parameters = [], $data = [])
{
if (is_array($url)) {
$data = $query_parameters;
Expand All @@ -295,7 +301,6 @@ public function delete($url, $query_parameters = [], $data = [])
if (!empty($data)) {
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
}
return $this->exec();
}

/**
Expand Down Expand Up @@ -605,6 +610,12 @@ public function execDone()
* @return mixed Returns the value provided by exec.
*/
public function get($url, $data = [])
{
$this->setGet($url, $data);
return $this->exec();
}

public function setGet($url, $data = [])
{
if (is_array($url)) {
$data = $url;
Expand All @@ -613,7 +624,6 @@ public function get($url, $data = [])
$this->setUrl($url, $data);
$this->setOptInternal(CURLOPT_CUSTOMREQUEST, 'GET');
$this->setOptInternal(CURLOPT_HTTPGET, true);
return $this->exec();
}

/**
Expand Down Expand Up @@ -642,6 +652,12 @@ public function getInfo($opt = null)
* @return mixed Returns the value provided by exec.
*/
public function head($url, $data = [])
{
$this->setHead($url, $data);
return $this->exec();
}

public function setHead($url, $data = [])
{
if (is_array($url)) {
$data = $url;
Expand All @@ -650,7 +666,6 @@ public function head($url, $data = [])
$this->setUrl($url, $data);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD');
$this->setOpt(CURLOPT_NOBODY, true);
return $this->exec();
}

/**
Expand All @@ -661,14 +676,19 @@ public function head($url, $data = [])
* @return mixed Returns the value provided by exec.
*/
public function options($url, $data = [])
{
$this->setOptions($url, $data);
return $this->exec();
}

public function setOptions($url, $data = [])
{
if (is_array($url)) {
$data = $url;
$url = (string)$this->url;
}
$this->setUrl($url, $data);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
return $this->exec();
}

/**
Expand All @@ -679,6 +699,12 @@ public function options($url, $data = [])
* @return mixed Returns the value provided by exec.
*/
public function patch($url, $data = [])
{
$this->setPatch($url, $data);
return $this->exec();
}

public function setPatch($url, $data = [])
{
if (is_array($url)) {
$data = $url;
Expand All @@ -692,7 +718,6 @@ public function patch($url, $data = [])
$this->setUrl($url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
return $this->exec();
}

/**
Expand Down Expand Up @@ -722,6 +747,12 @@ public function patch($url, $data = [])
* [3] http://php.net/ChangeLog-5.php#5.5.11
*/
public function post($url, $data = '', $follow_303_with_post = false)
{
$this->setPost($url, $data, $follow_303_with_post);
return $this->exec();
}

public function setPost($url, $data = '', $follow_303_with_post = false)
{
if (is_array($url)) {
$follow_303_with_post = (bool)$data;
Expand All @@ -746,7 +777,6 @@ public function post($url, $data = '', $follow_303_with_post = false)

$this->setOpt(CURLOPT_POST, true);
$this->setOpt(CURLOPT_POSTFIELDS, $this->buildPostData($data));
return $this->exec();
}

/**
Expand All @@ -757,6 +787,12 @@ public function post($url, $data = '', $follow_303_with_post = false)
* @return mixed Returns the value provided by exec.
*/
public function put($url, $data = [])
{
$this->setPut($url, $data);
return $this->exec();
}

public function setPut($url, $data = [])
{
if (is_array($url)) {
$data = $url;
Expand All @@ -773,7 +809,6 @@ public function put($url, $data = [])
if (!empty($put_data)) {
$this->setOpt(CURLOPT_POSTFIELDS, $put_data);
}
return $this->exec();
}

/**
Expand All @@ -784,6 +819,12 @@ public function put($url, $data = [])
* @return mixed Returns the value provided by exec.
*/
public function search($url, $data = [])
{
$this->setSearch($url, $data);
return $this->exec();
}

public function setSearch($url, $data = [])
{
if (is_array($url)) {
$data = $url;
Expand All @@ -800,7 +841,6 @@ public function search($url, $data = [])
if (!empty($put_data)) {
$this->setOpt(CURLOPT_POSTFIELDS, $put_data);
}
return $this->exec();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/run_phpunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export PHP_CURL_CLASS_TEST_MODE_ENABLED="yes"
# Start test servers. Run servers on different ports to allow simultaneous
# requests without blocking.
server_count=7
declare -A pids
for i in $(seq 0 $(("${server_count}" - 1))); do
pids=()
for i in $(seq 0 "$(echo "${server_count} - 1" | bc)"); do
port=8000
(( port += $i ))

php -S "127.0.0.1:${port}" server.php &> /dev/null &
pids["${i}"]="${!}"
pids+=("${!}")
done

# Determine which phpunit to use.
Expand Down