Bug #77535 [NEW]: Invalid callback, h2 server push
| From: | tobias dot nyholm at gmail dot com | Date: | Mon, 28 Jan 2019 19:21:59 +0000 |
| Subject: | Bug #77535 [NEW]: Invalid callback, h2 server push | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219253@lists.php.net to get a copy of this message | ||
From: tobias dot nyholm at gmail dot com
Operating system:
PHP version: master-Git-2019-01-28 (Git)
Package: cURL related
Bug Type: Bug
Bug description:Invalid callback, h2 server push
Description:
------------
When I set my callback in a different function I get a warning. I cannot
figure out why.
If I move the contents of addServerPushCallback() to sendRequest() then
I wont have the same issue.
Test script:
---------------
<?php
class MyHttpClient
{
private $mh;
private $curl;
public function sendRequest()
{
if (false === $this->mh = curl_multi_init()) {
throw new \RuntimeException('Unable to create a new cURL
multi handle');
}
// FIXME Using a function like this does not work. If we inline
the contents of addServerPushCallback(), then we got no problem
$this->addServerPushCallback();
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP |
CURLPROTO_HTTPS);
curl_setopt($this->curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP
| CURLPROTO_HTTPS);
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($this->curl, CURLOPT_FAILONERROR, false);
curl_setopt($this->curl, CURLOPT_URL,
'https://http2.golang.org/serverpush');
curl_setopt($this->curl, CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_2_0);
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($ch,
$data) {
return \strlen($data);
});
curl_setopt($this->curl, CURLOPT_WRITEFUNCTION, function ($ch,
$data) {
return \strlen($data);
});
curl_multi_add_handle($this->mh, $this->curl);
$stillRunning = null;
while (true) {
do {
$mrc = curl_multi_exec($this->mh, $stillRunning);
} while (CURLM_CALL_MULTI_PERFORM === $mrc);
$info = curl_multi_info_read($this->mh);
while (false !== $info && $info['msg'] == CURLMSG_DONE) {
if (CURLMSG_DONE !== $info['msg']) {
continue;
}
die("Start handle request. ");
}
}
}
private function addServerPushCallback(): void
{
$callback = static function () {
return CURL_PUSH_OK;
};
curl_multi_setopt($this->mh, CURLMOPT_PIPELINING,
CURLPIPE_MULTIPLEX);
curl_multi_setopt($this->mh, CURLMOPT_PUSHFUNCTION, $callback);
}
}
$buzz = new MyHttpClient();
$buzz->sendRequest();
Expected result:
----------------
Output only "Start handle request."
Actual result:
--------------
Warning: Invalid callback , no array or string given in
/usr/src/myapp/test.php on line 40
Warning: curl_multi_exec(): Cannot call the CURLMOPT_PUSHFUNCTION in
/usr/src/myapp/test.php on line 40
--
Edit bug report at https://bugs.php.net/bug.php?id=77535&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77535&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77535&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77535&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77535&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77535&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77535&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77535&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77535&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77535&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77535&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77535&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77535&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77535&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77535&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77535&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77535&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77535&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77535&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77535&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77535&r=mysqlcfg