Skip to content
Closed
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
2 changes: 2 additions & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,8 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
if (Z_TYPE(retval) == IS_STRING) {
length = MIN((int) (size * nmemb), Z_STRLEN(retval));
memcpy(data, Z_STRVAL(retval), length);
} else if (Z_TYPE(retval) == IS_LONG) {
Copy link
Member

@kocsismate kocsismate Feb 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how difficult is it to add a test for the usage of CURL_READFUNC_PAUSE? it would be nice to have one I guess unless it's very compilcated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added one, that I know test the code, but what I don't like about it is that there is no way to know that the read is paused. But I guess it's better than nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's definitely better! Would it make sense to return CURL_READFUNC_PAUSE until a specific amount of time elapses (e.g. 1 sec)? If this makes sense then the test should be tagged as slow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CURLOPT_READFUNCTION callback is not called after returning CURL_READFUNC_PAUSE until curl_pause(CURLPAUSE_CONT) is called. So I don't think that it will really improve the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then!

length = Z_LVAL_P(&retval);
}
zval_ptr_dtor(&retval);
}
Expand Down
47 changes: 47 additions & 0 deletions ext/curl/tests/curl_pause_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
Test CURL_READFUNC_PAUSE and curl_pause()
--EXTENSIONS--
curl
--FILE--
<?php
include 'server.inc';
$host = curl_cli_server_start();

class Input {
private static $RESPONSES = [
'Foo bar ',
CURL_READFUNC_PAUSE,
'baz qux',
null
];
private int $res = 0;
public function __invoke($ch, $hReadHandle, $iMaxOut)
{
return self::$RESPONSES[$this->res++];
}
}

$inputHandle = fopen(__FILE__, 'r');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=input");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_READFUNCTION, new Input);
curl_setopt($ch, CURLOPT_INFILE, $inputHandle);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$mh = curl_multi_init();
curl_multi_add_handle($mh, $ch);
do {
$status = curl_multi_exec($mh, $active);
curl_pause($ch, CURLPAUSE_CONT);
if ($active) {
usleep(100);
curl_multi_select($mh);
}
} while ($active && $status == CURLM_OK);

echo curl_multi_getcontent($ch);
?>
--EXPECT--
string(15) "Foo bar baz qux"
3 changes: 3 additions & 0 deletions ext/curl/tests/responder/get.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
case 'post':
var_dump($_POST);
break;
case 'input':
var_dump(file_get_contents('php://input'));
break;
case 'getpost':
var_dump($_GET);
var_dump($_POST);
Expand Down