Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17932 > unrolled thread
| Started by | JJ <jj4public@vfemail.net> |
|---|---|
| First post | 2019-06-05 10:45 +0700 |
| Last post | 2019-06-12 22:25 +0200 |
| Articles | 20 on this page of 41 — 6 participants |
Back to article view | Back to comp.lang.php
How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-05 10:45 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? "J.O. Aho" <user@example.net> - 2019-06-05 06:54 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-06 18:55 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-06 18:52 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-07 19:10 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-07 15:26 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-08 13:15 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-08 13:35 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-08 11:58 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-09 08:46 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-09 22:10 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-09 22:13 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-10 20:42 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-11 13:15 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-12 05:51 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-12 10:37 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-12 22:11 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-11 18:24 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-08 13:20 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-09 09:08 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Jerry Stuckle <jstucklex@attglobal.net> - 2019-06-09 22:12 -0400
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-11 18:05 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-11 20:19 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-08 13:19 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-08 13:37 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-09 09:41 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-10 20:32 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-10 16:34 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-10 16:38 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-10 16:57 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-11 12:42 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-11 08:18 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-12 05:51 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-05 21:35 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Arno Welzel <usenet@arnowelzel.de> - 2019-06-12 08:54 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-12 18:07 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-12 21:51 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Arno Welzel <usenet@arnowelzel.de> - 2019-06-12 17:12 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? JJ <jj4public@vfemail.net> - 2019-06-13 00:12 +0700
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Arno Welzel <usenet@arnowelzel.de> - 2019-06-12 16:59 +0200
Re: How to handle curl_exec() so that it won't terminat my script abruptly without any exception? Luuk <luuk@invalid.lan> - 2019-06-12 22:25 +0200
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2019-06-09 22:12 -0400 |
| Message-ID | <qdkea8$rbp$2@jstuckle.eternal-september.org> |
| In reply to | #17947 |
On 6/8/2019 10:08 PM, JJ wrote: > On Sat, 08 Jun 2019 13:20:50 +0200, Thomas 'PointedEars' Lahn wrote: >> >> You probably mean php.ini. Note that there are several php.ini files, and >> that it can contain includes. phpinfo() will tell you what you are using. > > I only have one `php.ini` file at: e:\xampp\php\php.ini > > phpinfo() shows `error_reporting` as `32767` for both Local and Master > values. > >> Strange. Where are errors configured to be logged? > > phpinfo() shows `error_log` as `\xampp\php\logs\php_error_log` for both > Local and Master values - which is same as: > > e:\xampp\php\logs\php_error_log > > I've already confirmed that it's the correct PHP error log file, because if > I do a call to a non existing function at the start of the script, the error > is logged into that file. > >> The behavior actually depends on the used command shell; there are (at >> least) three for Microsoft Windows: command.com, cmd.exe, and Microsoft >> PowerShell (you can also have e.g. a Bash, e.g. with Cygwin or Git for >> Windows installed). But if it were a complete command, it would also not >> work on Unices. > > I'm using CMD.EXE in 64-bit Windows 7. I only use other shell when I have > to. > >> You are still not posting using your real name. > > Sorry if it offends you. > I need to protect myself. I believe I have rights for that. > And don't worry about "Pointed Head" not liking your name. He's a well-known troll with little of anything useful to add to conversations. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2019-06-11 18:05 +0200 |
| Message-ID | <5258006.DvuYhMxLoT@PointedEars.de> |
| In reply to | #17947 |
JJ wrote: > On Sat, 08 Jun 2019 13:20:50 +0200, Thomas 'PointedEars' Lahn wrote: >> You probably mean php.ini. Note that there are several php.ini files, >> and that it can contain includes. phpinfo() will tell you what you are >> using. > > I only have one `php.ini` file at: e:\xampp\php\php.ini The one you *have* is not necessarily the one that you/PHP are *using*. And even if php.ini has one value for a setting, an include referred by it can have another. > phpinfo() shows `error_reporting` as `32767` for both Local and Master > values. 32767 is the value of E_ALL, so since you are using PHP 7.x all errors should be reported. <https://www.php.net/manual/en/errorfunc.constants.php> >> Strange. Where are errors configured to be logged? > > phpinfo() shows `error_log` as `\xampp\php\logs\php_error_log` for both > Local and Master values - which is same as: > > e:\xampp\php\logs\php_error_log > > I've already confirmed that it's the correct PHP error log file, because > if I do a call to a non existing function at the start of the script, the > error is logged into that file. OK. Then if the above does not help, I am out of ideas, except: Try to find a pattern in what you called “some websites”. There is always a reason why something does not work. >> The behavior actually depends on the used command shell; there are (at >> least) three for Microsoft Windows: command.com, cmd.exe, and Microsoft >> PowerShell (you can also have e.g. a Bash, e.g. with Cygwin or Git for >> Windows installed). But if it were a complete command, it would also not >> work on Unices. > > I'm using CMD.EXE in 64-bit Windows 7. I only use other shell when I have > to. OK. >> You are still not posting using your real name. > > Sorry if it offends you. It is certainly not acceptable talking to a pseudonymous. “JJ” could easily be “KK” tomorrow. > I need to protect myself. Sounds paranoid. On which grounds do you think you need this *pseudo*- protection (no pun intended)? -- PointedEars Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-11 20:19 +0200 |
| Message-ID | <5cfff0be$0$22356$e4fe514c@news.xs4all.nl> |
| In reply to | #17969 |
On 11-6-2019 18:05, Thomas 'PointedEars' Lahn wrote: >>> You are still not posting using your real name. >> Sorry if it offends you. > It is certainly not acceptable talking to a pseudonymous. “JJ” could easily > be “KK” tomorrow. > Yes, and `Thomas 'PointedEars' Lahn` can also be “KK” tomorrow! So, what's your point? -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-08 13:19 +0700 |
| Message-ID | <t8cqgtm5vxxx.t0lvrrnmg73b$.dlg@40tude.net> |
| In reply to | #17939 |
On Fri, 07 Jun 2019 15:26:57 +0200, Thomas 'PointedEars' Lahn wrote: > > Because my guess is that something is wrong with the security certificates > on your machine. I've already imported the certificate mentioned by below SO answer, into the Trusted Root Certification Authorities store. https://stackoverflow.com/a/21114601/1510085
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-08 13:37 +0700 |
| Message-ID | <uhzg9zmwwugk.l2g6sb4kkvp1$.dlg@40tude.net> |
| In reply to | #17941 |
On Sat, 8 Jun 2019 13:19:08 +0700, JJ wrote: > On Fri, 07 Jun 2019 15:26:57 +0200, Thomas 'PointedEars' Lahn wrote: >> >> Because my guess is that something is wrong with the security certificates >> on your machine. > > I've already imported the certificate mentioned by below SO answer, into the > Trusted Root Certification Authorities store. > > https://stackoverflow.com/a/21114601/1510085 If I run curl with below command line. curl https://www.youtube.com/ It works fine and it outputs YouTube's HTML data. No error/warning is outputted.
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-09 09:41 +0200 |
| Message-ID | <5cfcb812$0$22340$e4fe514c@news.xs4all.nl> |
| In reply to | #17941 |
On 8-6-2019 08:19, JJ wrote: > On Fri, 07 Jun 2019 15:26:57 +0200, Thomas 'PointedEars' Lahn wrote: >> >> Because my guess is that something is wrong with the security certificates >> on your machine. > > I've already imported the certificate mentioned by below SO answer, into the > Trusted Root Certification Authorities store. > > https://stackoverflow.com/a/21114601/1510085 > What is the output of PHP -i ? It should include 'curl.cainfo', importing to Windows certificate store is not mentioned in above SO answer. curl cURL support => enabled cURL Information => 7.64.0 curl.cainfo => d:\php\cacert.pem => d:\php\cacert.pem -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-10 20:32 +0700 |
| Message-ID | <10oe5tf3cxbjw$.kqcgz8646c70.dlg@40tude.net> |
| In reply to | #17948 |
On Sun, 9 Jun 2019 09:41:08 +0200, Luuk wrote: > > What is the output of PHP -i ? > > It should include 'curl.cainfo', importing to Windows certificate store > is not mentioned in above SO answer. > > curl > cURL support => enabled > cURL Information => 7.64.0 > curl.cainfo => d:\php\cacert.pem => d:\php\cacert.pem Here's the output for: php -i https://pastebin.com/UykrZrxB FYI, I've already replaced the `curl-ca-bundle.crt` file with the one from SO, then restarted the Apache server.
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-10 16:34 +0200 |
| Message-ID | <5cfe6a71$0$22348$e4fe514c@news.xs4all.nl> |
| In reply to | #17960 |
On 10-6-2019 15:32, JJ wrote: > On Sun, 9 Jun 2019 09:41:08 +0200, Luuk wrote: >> >> What is the output of PHP -i ? >> >> It should include 'curl.cainfo', importing to Windows certificate store >> is not mentioned in above SO answer. >> >> curl >> cURL support => enabled >> cURL Information => 7.64.0 >> curl.cainfo => d:\php\cacert.pem => d:\php\cacert.pem > > Here's the output for: php -i > > https://pastebin.com/UykrZrxB > > FYI, I've already replaced the `curl-ca-bundle.crt` file with the one from > SO, then restarted the Apache server. > With your code (date: Wed, 5 Jun 2019 10:45:52 +0700) and the modifications from J.O.Aho (date: Wed, 5 Jun 2019 06:54:44 +0200 ) and after enabling curl under php, i do get results. I do get results, even if i do that via IIS (url: http://localhost/curl.php ) The CSS and/or Javascript is not loaded, thus it looks like ... -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-10 16:38 +0200 |
| Message-ID | <5cfe6b6b$0$22349$e4fe514c@news.xs4all.nl> |
| In reply to | #17962 |
On 10-6-2019 16:34, Luuk wrote: > > With your code (date: Wed, 5 Jun 2019 10:45:52 +0700) > and the modifications from J.O.Aho (date: Wed, 5 Jun 2019 06:54:44 +0200 ) https://pastebin.com/H42dEr2B -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-10 16:57 +0200 |
| Message-ID | <5cfe6fe2$0$22362$e4fe514c@news.xs4all.nl> |
| In reply to | #17963 |
On 10-6-2019 16:38, Luuk wrote: > On 10-6-2019 16:34, Luuk wrote: > >> >> With your code (date: Wed, 5 Jun 2019 10:45:52 +0700) >> and the modifications from J.O.Aho (date: Wed, 5 Jun 2019 06:54:44 >> +0200 ) > > https://pastebin.com/H42dEr2B > > > Also, would you like to check if the code posted here: https://pastebin.com/0qLMz782 works for you or, if you get an error, which error do you get? (example code from: https://www.youtube.com/watch?v=OXiaZVOys2k ) -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-11 12:42 +0700 |
| Message-ID | <tctk5hq8ol8a.1jiqyua46ghwn.dlg@40tude.net> |
| In reply to | #17964 |
On Mon, 10 Jun 2019 16:57:38 +0200, Luuk wrote: > On 10-6-2019 16:38, Luuk wrote: >> On 10-6-2019 16:34, Luuk wrote: >> >>> >>> With your code (date: Wed, 5 Jun 2019 10:45:52 +0700) >>> and the modifications from J.O.Aho (date: Wed, 5 Jun 2019 06:54:44 >>> +0200 ) >> >> https://pastebin.com/H42dEr2B >> > > Also, would you like to check if the code posted here: > https://pastebin.com/0qLMz782 > > works for you or, if you get an error, which error do you get? > > (example code from: https://www.youtube.com/watch?v=OXiaZVOys2k ) Both code works, but none of them produce the same error. This thread is about handling the error. It's not about fixing the error.
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2019-06-11 08:18 +0200 |
| Message-ID | <5cff47b6$0$22362$e4fe514c@news.xs4all.nl> |
| In reply to | #17966 |
On 11-6-2019 07:42, JJ wrote: > On Mon, 10 Jun 2019 16:57:38 +0200, Luuk wrote: >> On 10-6-2019 16:38, Luuk wrote: >>> On 10-6-2019 16:34, Luuk wrote: >>> >>>> >>>> With your code (date: Wed, 5 Jun 2019 10:45:52 +0700) >>>> and the modifications from J.O.Aho (date: Wed, 5 Jun 2019 06:54:44 >>>> +0200 ) >>> >>> https://pastebin.com/H42dEr2B >>> >> >> Also, would you like to check if the code posted here: >> https://pastebin.com/0qLMz782 >> >> works for you or, if you get an error, which error do you get? >> >> (example code from: https://www.youtube.com/watch?v=OXiaZVOys2k ) > > Both code works, but none of them produce the same error. If they both work, than they do not produce the same error. A working piece of code should not produce an error. > This thread is about handling the error. It's not about fixing the error. > I am sorry, but i must have missed what error are you talking about. -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-12 05:51 +0700 |
| Message-ID | <6bbelm97memi.5iuw4b8tvh5v.dlg@40tude.net> |
| In reply to | #17967 |
On Tue, 11 Jun 2019 08:18:28 +0200, Luuk wrote: > > I am sorry, but i must have missed what error are you talking about. The script terminates abuptly at `curl_exec()`. Any code after that is not executed. The proof is that when I do a call to a non existing function after `curl_exec()`, no error is logged due to function call to non existant function. And putting the same non existant function call before `curl_exec()`, does create an error log.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2019-06-05 21:35 +0200 |
| Message-ID | <5281068.DvuYhMxLoT@PointedEars.de> |
| In reply to | #17932 |
JJ wrote:
> I'm trying to make a simple proxy script for my web server in my local
> network, but I've found that `curl_exec()` abruptly terminates my script
> without any error or exception on some websites.
^^^^^^^^^^^^^^^^
> FYI, my PHP application came from XAMPP
> (xampp-portable-win32-7.3.2-0-VC15).
>
> Here's the simplified script to reproduce the problem.
>
> <?php
> function doResponseHeaders($cu, $dt) {
> header($dt);
> return strlen($dt);
> }
> $cu = curl_init('https://www.youtube.com/');
> curl_setopt($cu, CURLOPT_HEADERFUNCTION, 'doResponseHeaders');
> try {
> echo 'CURL = ' . curl_exec($cu);
> } catch (Exception $e) {
> echo 'CURL_EXCEPTION';
> }
> curl_close($cu);
> echo 'ALL_DONE';
> ?>
>
> When run, the HTTP 200 is returned, but there is no HTTP body.
At first I thought it would be the usual: YouTube would not take kindly to
being accessed by non-browsers. But:
| $ curl --user-agent 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
| (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36'
| http://www.youtube.com/
| $
[empty]
The reason why this "does not work" “with some Web sites” is very simple:
| $ HEAD -USe http://www.youtube.com/
| HEAD http://www.youtube.com/
| User-Agent: lwp-request/6.15 libwww-perl/6.15
|
| 301 Moved Permanently
^^^^^^^^^^^^^^^^^^^^^
| Cache-Control: no-cache
| Connection: close
| Date: Wed, 05 Jun 2019 19:20:54 GMT
| Location: https://www.youtube.com/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Server: YouTube Frontend Proxy
| Content-Length: 0
| […]
The insecure access is being redirected to the secure Web site, and your
curl_exec() call does not handle that. Without following the redirection,
the HTTP body actually *is* empty.
> I did found out that the problem doesn't occur if I don't let the
> `Transfer-Encoding` HTTP response header be processed by `header()`.
> However, the main problem is the fact that `curl_exec()` terminates the
> script abruptly without any exception.
> And **any** code after `curl_exec()` is not executed.
Unlikely.
> So, how to handle this kind of error so that it won't terminate the
> script?
You can set CURLOPT_FOLLOWLOCATION to TRUE (and fine-tune e.g. with
CURLOPT_MAXREDIRS), and you should probably do that (so that it works even
if YouTube etc. changes their mind again; but the simplest solution is to
use 'https://www.youtube.com/' etc. in the first place.
Next time, look at the response status code first.
<https://php.net/curl>
Your From is borked.
--
PointedEars
Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-12 08:54 +0200 |
| Message-ID | <gmblsaFqtr4U1@mid.individual.net> |
| In reply to | #17932 |
JJ:
> I'm trying to make a simple proxy script for my web server in my local
> network, but I've found that `curl_exec()` abruptly terminates my script
> without any error or exception on some websites.
[...]
In addition to everything else already discussed here:
> FYI, my PHP application came from XAMPP (xampp-portable-win32-7.3.2-0-VC15).
>
> Here's the simplified script to reproduce the problem.
>
> <?php
> function doResponseHeaders($cu, $dt) {
> header($dt);
> return strlen($dt);
> }
> $cu = curl_init('https://www.youtube.com/');
> curl_setopt($cu, CURLOPT_HEADERFUNCTION, 'doResponseHeaders');
> try {
> echo 'CURL = ' . curl_exec($cu);
> } catch (Exception $e) {
> echo 'CURL_EXCEPTION';
> }
> curl_close($cu);
> echo 'ALL_DONE';
> ?>
>
> When run, the HTTP 200 is returned, but there is no HTTP body.
This works fine for me here (Linux with Apache 2.4, PHP 7.2 as FPM):
<https://arnowelzel.de/samples/youtube-proxy.php>
So to me this looks like a bug somewhere in the Windows port of PHP or
the Curl extension which can't be mitigated.
Instead of using XAMPP I would try to install Apache 2.4 and PHP 7.3
separately - it's not that hard to configure Apache and PHP manually.
But this way you can be sure that there is no additional problem with
the runtime environment.
Even better: use Linux and not Windows. The Windows ports are not tested
as well as the Linux versions and may behave in a different way.
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-12 18:07 +0700 |
| Message-ID | <1gazo807tr0ns.11mjjbvt58nuo$.dlg@40tude.net> |
| In reply to | #17977 |
On Wed, 12 Jun 2019 08:54:02 +0200, Arno Welzel wrote: > > This works fine for me here (Linux with Apache 2.4, PHP 7.2 as FPM): > > <https://arnowelzel.de/samples/youtube-proxy.php> > > So to me this looks like a bug somewhere in the Windows port of PHP or > the Curl extension which can't be mitigated. > > Instead of using XAMPP I would try to install Apache 2.4 and PHP 7.3 > separately - it's not that hard to configure Apache and PHP manually. > But this way you can be sure that there is no additional problem with > the runtime environment. I've just tested XAMPP with the same version under Ubuntu in a VM. The problem doesn not exist in linux platform. Only in Windows. I didn't find any Windows platform "gotchas" in the PHP documentations. So, this problem kind of catches me by surprise. > Even better: use Linux and not Windows. The Windows ports are not tested > as well as the Linux versions and may behave in a different way. I know. All of the softwares involved originates from *nix platform after all. But linux is not an option for me, unfortunately.
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-12 21:51 +0700 |
| Message-ID | <10oewlg9578xy$.s8pgkwjte4bv.dlg@40tude.net> |
| In reply to | #17978 |
On Wed, 12 Jun 2019 18:07:22 +0700, JJ wrote: > > I've just tested XAMPP with the same version under Ubuntu in a VM. The > problem doesn not exist in linux platform. Only in Windows. > > I didn't find any Windows platform "gotchas" in the PHP documentations. So, > this problem kind of catches me by surprise. If I execute the script from the command line like below, it works properly. php -f test.php It outputs the correct HTML data, and at the end of it is: CURL = 1ALL_DONE So, because the command line and Apache module versions behave differently, I could only suspect that the Apache module version is either not configured properly, or it has a bug in its implementation. FYI, this is the Apache's `httpd.conf` file. https://pastebin.com/R7TgnkEf And this is XAMPP's `httpd-xampp.conf` file which is referred by `httpd.conf` file using `Include` directive, and it's the one that contains the PHP module configuration. https://pastebin.com/d3Hdmut9
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-12 17:12 +0200 |
| Message-ID | <gmcj37F2i7rU1@mid.individual.net> |
| In reply to | #17981 |
On 12.06.19 16:51, JJ wrote:
[...]
> So, because the command line and Apache module versions behave differently,
> I could only suspect that the Apache module version is either not configured
> properly, or it has a bug in its implementation.
Yes, this would not be unusual. It would never recommend using PHP as an
Apache module anyway. You may gain speed since PHP as an external CGI
handler has to be started with every request - but even in Windows it is
possible to use PPH-FPM if performance is an issue:
<https://www.orbitale.io/2017/11/11/apache-and-php-fpm-in-windows.html>
But first I would configure PHP as CGI - just to avoid the issues with
the Apache module. For example if PHP is in c:\php the minimum required
options in Apache would be to enable "mod_alias" and then use this:
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"
Also see <https://httpd.apache.org/docs/2.4/mod/mod_alias.html#scriptalias>
If this works, you can try to set up PHP as FPM as a next step. This
should increase performance significantly, since PHP will run as a
service besides Apache and does not have to start as a CGI process with
every single request.
> FYI, this is the Apache's `httpd.conf` file.
[...]
> https://pastebin.com/R7TgnkEf
[...]
> https://pastebin.com/d3Hdmut9
If you want to remove the PHP module and use PHP as CGI as described
above, comment out these lines:
LoadFile "/xampp/php/php7ts.dll"
LoadFile "/xampp/php/libpq.dll"
LoadModule php7_module "/xampp/php/php7apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-13 00:12 +0700 |
| Message-ID | <1nx13uhfumywx$.1215umpsj38qe$.dlg@40tude.net> |
| In reply to | #17984 |
On Wed, 12 Jun 2019 17:12:39 +0200, Arno Welzel wrote: > > Yes, this would not be unusual. It would never recommend using PHP as an > Apache module anyway. You may gain speed since PHP as an external CGI > handler has to be started with every request - but even in Windows it is > possible to use PPH-FPM if performance is an issue: > > <https://www.orbitale.io/2017/11/11/apache-and-php-fpm-in-windows.html> > > But first I would configure PHP as CGI - just to avoid the issues with > the Apache module. For example if PHP is in c:\php the minimum required > options in Apache would be to enable "mod_alias" and then use this: > > ScriptAlias /php/ "c:/php/" > AddType application/x-httpd-php .php > Action application/x-httpd-php "/php/php-cgi.exe" > > Also see <https://httpd.apache.org/docs/2.4/mod/mod_alias.html#scriptalias> > > If this works, you can try to set up PHP as FPM as a next step. This > should increase performance significantly, since PHP will run as a > service besides Apache and does not have to start as a CGI process with > every single request. > If you want to remove the PHP module and use PHP as CGI as described > above, comment out these lines: > > LoadFile "/xampp/php/php7ts.dll" > LoadFile "/xampp/php/libpq.dll" > LoadModule php7_module "/xampp/php/php7apache2_4.dll" > > <FilesMatch "\.php$"> > SetHandler application/x-httpd-php > </FilesMatch> > <FilesMatch "\.phps$"> > SetHandler application/x-httpd-php-source > </FilesMatch> I just tested your solution, and darn it. It's the same result. But because of this and some further testings, I finally found the problem. It was me. I misinterpreted the problem. And I paid that with my embarrassment. It turns out that the script did finish completely after I changed it create a subdirectory at the very end of the script. Because the subdirectory is created by the script after I open the script from the browser. The fact that the browser got chunk encoding error is because YouTube returns chunked data. cURL decodes it automatically, and outputs the data without any encoding. But the `doResponseHeader` function passes the `Transfer-Encoding: chunked` header to the browser. So, the browser decodes the data then fails. So, there's no content. I thank everyone who share their precious time to help me solve this problem. So, thank you, and have a good day.
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-12 16:59 +0200 |
| Message-ID | <gmci9nF2cunU1@mid.individual.net> |
| In reply to | #17978 |
On 12.06.19 13:07, JJ wrote: [...] > I've just tested XAMPP with the same version under Ubuntu in a VM. The > problem doesn not exist in linux platform. Only in Windows. [...] > I know. All of the softwares involved originates from *nix platform after > all. But linux is not an option for me, unfortunately. Well - since it is clear that the problem is the Windows port I think you are out of options. Maybe you will find another version of PHP or Curl which works better. But there is no way to avoid the crash from inside the PHP script itself. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.php
csiph-web