Error occurred when post data via PHP7 with cURL by HTTP/2

Allen Tsao <[email protected]> Mon, 18 Apr 2016 21:18:31 +0000
Newsgroups gmane.comp.web.curl.php
Message-ID <CAN31VeVVREKe-JAxoPGjyBxdCYP6U=FRqGLeq6dbMcMQoyNEgQ@mail.gmail.com>
--===============0142827418==
Content-Type: multipart/alternative; boundary=001a113ef4520622e50530c8e7ed

--001a113ef4520622e50530c8e7ed
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi all,

I got error message when I send push message to APNs via PHP7+cURL.

error message: =EF=BF=BD@@=EF=BF=BDHTTP/2 client preface string missing or =
corrupt. Hex
dump for received bytes:

I guess it's because of PHP7 but not very sure. with phpinfo() I can see
that no mod_ssl loaded but from Internet it says PHP7 support ssl by nature
so openssl.so is not existed in system any more. Also it's strange with
phpinfo() I saw the openssl version is 1.0.1e which is coming with redhat7,
not the one I installed from source.

btw, I installed php7 by yum, and the rest, openssl, nghttp, curl installed
from source.

please help to take a look.

php codes:

$ch =3D curl_init();

curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);//curl_setopt($ch,
CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $alert);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic"));
curl_setopt($ch, CURLOPT_SSLCERT, $pemfile);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pempwd);
$response =3D curl_exec($ch);

The server is REDHAT 7. The environment info can be found as below. $
openssl version OpenSSL 1.0.2g 1 Mar 2016

curl --version curl 7.48.0 (x86_64-pc-linux-gnu) libcurl/7.48.0
OpenSSL/1.0.2g nghttp2/1.9.2 Protocols: dict file ftp ftps gopher http
https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features:
IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets

$ php --version PHP 7.0.5 (cli) (built: Apr 2 2016 13:08:13) ( NTS )
Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c)
1998-2016 Zend Technologies

$ curl --http2 -I https://nghttp2.org HTTP/2.0 200 date:Sun, 17 Apr 2016
13:15:27 GMT content-type:text/html last-modified:Sat, 16 Apr 2016 14:56:04
GMT etag:"57125284-1a0a" accept-ranges:bytes content-length:6666
x-backend-header-rtt:0.001459 strict-transport-security:max-age=3D31536000
server:nghttpx nghttp2/1.10.0-DEV via:2 nghttpx x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=3Dblock x-content-type-options:nosniff

Even I can use command line to send push message to my phone: curl -d
'{"aps":{"alert":"test message","sound":"default"}}' --cert
/xxx/xxx.pem:xxxx -H "apns-topic:chs.itsme" --http2
https://api.development.push.apple.com/3/device/85f0257xxxxx


Any help will be appreciated.

Regards,

Allen

--001a113ef4520622e50530c8e7ed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span style=3D"font-size:12.8px">Hi all,</span><div style=
=3D"font-size:12.8px"><br></div><div style=3D"font-size:12.8px"><p style=3D=
"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:=
rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-ser=
if;line-height:19.5px">I got error message when I send push message to APNs=
 via PHP7+cURL.</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;fo=
nt-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,&#39;Helvetic=
a Neue&#39;,Helvetica,sans-serif;line-height:19.5px">error message: =EF=BF=
=BD@@=EF=BF=BDHTTP/2 client preface string missing or corrupt. Hex dump for=
 received bytes:</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;f=
ont-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,&#39;Helveti=
ca Neue&#39;,Helvetica,sans-serif;line-height:19.5px">I guess it&#39;s beca=
use of PHP7 but not very sure. with phpinfo() I can see that no mod_ssl loa=
ded but from Internet it says PHP7 support ssl by nature so openssl.so is n=
ot existed in system any more. Also it&#39;s strange with phpinfo() I saw t=
he openssl version is 1.0.1e which is coming with redhat7, not the one I in=
stalled from source.</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0=
px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,&#39;Hel=
vetica Neue&#39;,Helvetica,sans-serif;line-height:19.5px">btw, I installed =
php7 by yum, and the rest, openssl, nghttp, curl installed from source.</p>=
<p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:=
both;color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helveti=
ca,sans-serif;line-height:19.5px">please help to take a look.</p><p style=
=3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;col=
or:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-=
serif;line-height:19.5px">php codes:</p><pre style=3D"white-space:pre-wrap;=
margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;widt=
h:auto;max-height:600px;overflow:auto;font-family:Consolas,Menlo,Monaco,&#3=
9;Lucida Console&#39;,&#39;Liberation Mono&#39;,&#39;DejaVu Sans Mono&#39;,=
&#39;Bitstream Vera Sans Mono&#39;,&#39;Courier New&#39;,monospace,sans-ser=
if;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(238,238,238)">=
<code style=3D"margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo=
,Monaco,&#39;Lucida Console&#39;,&#39;Liberation Mono&#39;,&#39;DejaVu Sans=
 Mono&#39;,&#39;Bitstream Vera Sans Mono&#39;,&#39;Courier New&#39;,monospa=
ce,sans-serif;white-space:inherit"><span style=3D"margin:0px;padding:0px;bo=
rder:0px;color:rgb(46,49,51)">$ch </span><span style=3D"margin:0px;padding:=
0px;border:0px;color:rgb(46,49,51)">=3D</span><span style=3D"margin:0px;pad=
ding:0px;border:0px;color:rgb(46,49,51)"> curl_init</span><span style=3D"ma=
rgin:0px;padding:0px;border:0px;color:rgb(46,49,51)">();</span><span style=
=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">

curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_HTTP_VERSION</span><span style=3D"margin:0=
px;padding:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"margi=
n:0px;padding:0px;border:0px;color:rgb(46,49,51)"> </span><span style=3D"ma=
rgin:0px;padding:0px;border:0px;color:rgb(107,41,27)">3</span><span style=
=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">);</span><span s=
tyle=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
</span><span style=3D"margin:0px;padding:0px;border:0px;color:rgb(132,138,1=
45)">//curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);</span=
><span style=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_URL</span><span style=3D"margin:0px;paddin=
g:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"margin:0px;pad=
ding:0px;border:0px;color:rgb(46,49,51)"> $url</span><span style=3D"margin:=
0px;padding:0px;border:0px;color:rgb(46,49,51)">);</span><span style=3D"mar=
gin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_POSTFIELDS</span><span style=3D"margin:0px=
;padding:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"margin:=
0px;padding:0px;border:0px;color:rgb(46,49,51)"> $alert</span><span style=
=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">);</span><span s=
tyle=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_HTTPHEADER</span><span style=3D"margin:0px=
;padding:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"margin:=
0px;padding:0px;border:0px;color:rgb(46,49,51)"> array</span><span style=3D=
"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">(</span><span style=
=3D"margin:0px;padding:0px;border:0px;color:rgb(107,41,27)">&quot;apns-topi=
c: $apns_topic&quot;</span><span style=3D"margin:0px;padding:0px;border:0px=
;color:rgb(46,49,51)">));</span><span style=3D"margin:0px;padding:0px;borde=
r:0px;color:rgb(46,49,51)">
curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_SSLCERT</span><span style=3D"margin:0px;pa=
dding:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"margin:0px=
;padding:0px;border:0px;color:rgb(46,49,51)"> $pemfile</span><span style=3D=
"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">);</span><span styl=
e=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
curl_setopt</span><span style=3D"margin:0px;padding:0px;border:0px;color:rg=
b(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;border:0px;color=
:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding:0px;border:0px;=
color:rgb(46,49,51)">,</span><span style=3D"margin:0px;padding:0px;border:0=
px;color:rgb(46,49,51)"> CURLOPT_SSLCERTPASSWD</span><span style=3D"margin:=
0px;padding:0px;border:0px;color:rgb(46,49,51)">,</span><span style=3D"marg=
in:0px;padding:0px;border:0px;color:rgb(46,49,51)"> $pempwd</span><span sty=
le=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">);</span><span=
 style=3D"margin:0px;padding:0px;border:0px;color:rgb(46,49,51)">
$response </span><span style=3D"margin:0px;padding:0px;border:0px;color:rgb=
(46,49,51)">=3D</span><span style=3D"margin:0px;padding:0px;border:0px;colo=
r:rgb(46,49,51)"> curl_exec</span><span style=3D"margin:0px;padding:0px;bor=
der:0px;color:rgb(46,49,51)">(</span><span style=3D"margin:0px;padding:0px;=
border:0px;color:rgb(46,49,51)">$ch</span><span style=3D"margin:0px;padding=
:0px;border:0px;color:rgb(46,49,51)">);</span></code></pre><p style=3D"marg=
in:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(3=
4,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;li=
ne-height:19.5px">The server is REDHAT 7. The environment info can be found=
 as below. $ openssl version OpenSSL 1.0.2g 1 Mar 2016</p><p style=3D"margi=
n:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34=
,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;lin=
e-height:19.5px">curl --version curl 7.48.0 (x86_64-pc-linux-gnu) libcurl/7=
.48.0 OpenSSL/1.0.2g nghttp2/1.9.2 Protocols: dict file ftp ftps gopher htt=
p https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features=
: IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP HTTP2 UnixSockets</p><p style=3D"=
margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:r=
gb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-seri=
f;line-height:19.5px">$ php --version PHP 7.0.5 (cli) (built: Apr 2 2016 13=
:08:13) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, C=
opyright (c) 1998-2016 Zend Technologies</p><p style=3D"margin:0px 0px 1em;=
padding:0px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-f=
amily:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;line-height:19.5p=
x">$ curl --http2 -I=C2=A0<a href=3D"https://nghttp2.org/" rel=3D"nofollow"=
 target=3D"_blank" style=3D"color:rgb(0,89,153);margin:0px;padding:0px;bord=
er:0px;text-decoration:none">https://nghttp2.org</a>=C2=A0HTTP/2.0 200 date=
:Sun, 17 Apr 2016 13:15:27 GMT content-type:text/html last-modified:Sat, 16=
 Apr 2016 14:56:04 GMT etag:&quot;57125284-1a0a&quot; accept-ranges:bytes c=
ontent-length:6666 x-backend-header-rtt:0.001459 strict-transport-security:=
max-age=3D31536000 server:nghttpx nghttp2/1.10.0-DEV via:2 nghttpx x-frame-=
options:SAMEORIGIN x-xss-protection:1; mode=3Dblock x-content-type-options:=
nosniff</p><p style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:=
15px;clear:both;color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#=
39;,Helvetica,sans-serif;line-height:19.5px">Even I can use command line to=
 send push message to my phone: curl -d &#39;{&quot;aps&quot;:{&quot;alert&=
quot;:&quot;test message&quot;,&quot;sound&quot;:&quot;default&quot;}}&#39;=
 --cert /xxx/xxx.pem:xxxx -H &quot;apns-topic:chs.itsme&quot; --http2<a hre=
f=3D"https://api.development.push.apple.com/3/device/85f0257xxxxx" rel=3D"n=
ofollow" target=3D"_blank" style=3D"color:rgb(0,89,153);margin:0px;padding:=
0px;border:0px;text-decoration:none">https://api.development.push.apple.com=
/3/device/85f0257xxxxx</a></p><p style=3D"margin:0px 0px 1em;padding:0px;bo=
rder:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Arial,&#=
39;Helvetica Neue&#39;,Helvetica,sans-serif;line-height:19.5px"><br></p><p =
style=3D"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:bot=
h;color:rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,=
sans-serif;line-height:19.5px">Any help will be appreciated.</p><p style=3D=
"margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:=
rgb(34,36,38);font-family:Arial,&#39;Helvetica Neue&#39;,Helvetica,sans-ser=
if;line-height:19.5px">Regards,</p><p style=3D"margin:0px 0px 1em;padding:0=
px;border:0px;font-size:15px;clear:both;color:rgb(34,36,38);font-family:Ari=
al,&#39;Helvetica Neue&#39;,Helvetica,sans-serif;line-height:19.5px">Allen<=
/p></div></div>

--001a113ef4520622e50530c8e7ed--

--===============0142827418==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KaHR0cDovL2Nv
b2wuaGF4eC5zZS9jZ2ktYmluL21haWxtYW4vbGlzdGluZm8vY3VybC1hbmQtcGhwCg==

--===============0142827418==--