Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17932 > unrolled thread

How to handle curl_exec() so that it won't terminat my script abruptly without any exception?

Started byJJ <jj4public@vfemail.net>
First post2019-06-05 10:45 +0700
Last post2019-06-12 22:25 +0200
Articles 20 on this page of 41 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  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 1 of 3  [1] 2 3  Next page →


#17932 — How to handle curl_exec() so that it won't terminat my script abruptly without any exception?

FromJJ <jj4public@vfemail.net>
Date2019-06-05 10:45 +0700
SubjectHow to handle curl_exec() so that it won't terminat my script abruptly without any exception?
Message-ID<1o3z8vwk6x9am$.54ia46ki18ga$.dlg@40tude.net>
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.

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.

So, how to handle this kind of error so that it won't terminate the script?

[toc] | [next] | [standalone]


#17933

From"J.O. Aho" <user@example.net>
Date2019-06-05 06:54 +0200
Message-ID<glp08kFpe9bU1@mid.individual.net>
In reply to#17932
On 05/06/2019 05.45, 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.

Don't think curl ever throws an exception.

> 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_FAILONERROR, true);

>    curl_setopt($cu, CURLOPT_HEADERFUNCTION, 'doResponseHeaders');

      if(curl_exec($cu) === false)
      {
          trigger_error(curl_error($cu));
      }

>    curl_close($cu);
>    echo 'ALL_DONE';
>    ?>

Hopefully you get an error to handle now.

-- 

  //Aho

[toc] | [prev] | [next] | [standalone]


#17935

FromJJ <jj4public@vfemail.net>
Date2019-06-06 18:55 +0700
Message-ID<6lo4ij2fqawt.1vh6y53d3gqs4$.dlg@40tude.net>
In reply to#17933
On Wed, 5 Jun 2019 06:54:44 +0200, J.O. Aho wrote:

> On 05/06/2019 05.45, 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.
> 
> Don't think curl ever throws an exception.
> 
>> 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_FAILONERROR, true);
> 
>>    curl_setopt($cu, CURLOPT_HEADERFUNCTION, 'doResponseHeaders');
> 
>       if(curl_exec($cu) === false)
>       {
>           trigger_error(curl_error($cu));
>       }
> 
>>    curl_close($cu);
>>    echo 'ALL_DONE';
>>    ?>
> 
> Hopefully you get an error to handle now.

Same result after I enabled the `CURLOPT_FAILONERROR` option, unfortunately.

If I do a function call to a non existing function before `curl_exec()`,
e.g.

  xyz_never_found();
  curl_exec($cu);

The error caused by that non existing function call is logged into the
`php_error_log`.

But if I put anywhere after `curl_exec()`, the error caused by that non
existing function call is not logged into the `php_error_log`. e.g.

  curl_exec($cu);
  xyz_never_found();

[toc] | [prev] | [next] | [standalone]


#17936

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2019-06-06 18:52 +0200
Message-ID<24788702.3NZrUQBIpf@PointedEars.de>
In reply to#17935
JJ wrote:

> But if I put anywhere after `curl_exec()`, the error caused by that non
> existing function call is not logged into the `php_error_log`. e.g.

Is a curl error logged instead?
 
>   curl_exec($cu);
>   xyz_never_found();

I cannot reproduce your problem using your (actual) code on my laptop, i.e.

| $ php -va
| PHP 7.0.33-0+deb9u3 (cli) (built: Mar  8 2019 10:01:24) ( NTS )
| Copyright (c) 1997-2017 The PHP Group
| Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
|     with Zend OPcache v7.0.33-0+deb9u3, Copyright (c) 1999-2017, by Zend
|     Technologies

What do you get if you use curl(1) instead?

-- 
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]


#17938

FromJJ <jj4public@vfemail.net>
Date2019-06-07 19:10 +0700
Message-ID<xgqfj59hcttl$.19poz68z331fq$.dlg@40tude.net>
In reply to#17936
On Thu, 06 Jun 2019 18:52:27 +0200, Thomas 'PointedEars' Lahn wrote:
> JJ wrote:
> 
>> But if I put anywhere after `curl_exec()`, the error caused by that non
>> existing function call is not logged into the `php_error_log`. e.g.
> 
> Is a curl error logged instead?

No. Nothing about curl is logged.

> I cannot reproduce your problem using your (actual) code on my laptop, i.e.
> 
>| $ php -va
>| PHP 7.0.33-0+deb9u3 (cli) (built: Mar  8 2019 10:01:24) ( NTS )
>| Copyright (c) 1997-2017 The PHP Group
>| Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
>|     with Zend OPcache v7.0.33-0+deb9u3, Copyright (c) 1999-2017, by Zend
>|     Technologies

Mine is:

  E:\xampp\php>php -va
  PHP 7.3.2 (cli) (built: Feb  5 2019 23:16:38) ( ZTS MSVC15 (Visual C++ 2017) x86 )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies

> What do you get if you use curl(1) instead?

If I replace this line:

  echo 'CURL = ' . curl_exec($cu);

With this:

  echo 'CURL = ' . curl(1);

It logged this.

  [07-Jun-2019 18:58:16 <censored>] PHP Warning:  curl_exec() expects parameter 1 to be resource, int given in E:\xampp\htdocs\test.php on line 9

And the web browser received this.

  Warning: curl_exec() expects parameter 1 to be resource, int given in E:\xampp\htdocs\test.php on line 9
  CURL = ALL_DONE

[toc] | [prev] | [next] | [standalone]


#17939

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2019-06-07 15:26 +0200
Message-ID<1871441.oMNUckLgyt@PointedEars.de>
In reply to#17938
JJ wrote:

> On Thu, 06 Jun 2019 18:52:27 +0200, Thomas 'PointedEars' Lahn wrote:
>> JJ wrote:
>>> But if I put anywhere after `curl_exec()`, the error caused by that non
>>> existing function call is not logged into the `php_error_log`. e.g.
>> Is a curl error logged instead?
> 
> No. Nothing about curl is logged.

What if you increase the log level?

>> I cannot reproduce your problem using your (actual) code on my laptop,
>> i.e.
>> 
>>| $ php -va

Not sure why I typed the “a” (interactive) there.  Fortunately, it is 
ignored then.

>> What do you get if you use curl(1) instead?
> 
> If I replace this line:
> 
>   echo 'CURL = ' . curl_exec($cu);
> 
> With this:
> 
>   echo 'CURL = ' . curl(1);

I am not talking about the PHP support for libcurl, but the original command 
line tool:

<https://curl.haxx.se/>

Because my guess is that something is wrong with the security certificates 
on your machine.
 
-- 
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]


#17940

FromJJ <jj4public@vfemail.net>
Date2019-06-08 13:15 +0700
Message-ID<x83zpaiv30t6$.1r9ikcr8k5mne$.dlg@40tude.net>
In reply to#17939
On Fri, 07 Jun 2019 15:26:57 +0200, Thomas 'PointedEars' Lahn wrote:
> 
> What if you increase the log level?

The default log level is `E_ALL` as specified in the `pnp.ini` file. I've
tried inserting below line at the top of the script, but still no error
logged.

  ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_STRICT);

>>> What do you get if you use curl(1) instead?
>> 
> I am not talking about the PHP support for libcurl, but the original command 
> line tool:

That command line would be errorneous in Windows platform. The whole
`curl(1)` would be considered as a filename, and the system will try to
search for `curl(1).exe` file. What's that `(1)` supposed to be? It's
neither a switch or an URL.

[toc] | [prev] | [next] | [standalone]


#17942

FromJJ <jj4public@vfemail.net>
Date2019-06-08 13:35 +0700
Message-ID<rs27hc9z7nqe.shryoy3chust.dlg@40tude.net>
In reply to#17940
On Sat, 8 Jun 2019 13:15:36 +0700, JJ wrote:
> 
>>>> What do you get if you use curl(1) instead?
>>> 
>> I am not talking about the PHP support for libcurl, but the original command 
>> line tool:
> 
> That command line would be errorneous in Windows platform. The whole
> `curl(1)` would be considered as a filename, and the system will try to
> search for `curl(1).exe` file. What's that `(1)` supposed to be? It's
> neither a switch or an URL.

If I run curl with below command line.

  curl http://localhost/test.php

It outputs below error.

  curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

[toc] | [prev] | [next] | [standalone]


#17945

FromJerry Stuckle <jstucklex@attglobal.net>
Date2019-06-08 11:58 -0400
Message-ID<qdglut$e02$1@jstuckle.eternal-september.org>
In reply to#17942
On 6/8/2019 2:35 AM, JJ wrote:
> On Sat, 8 Jun 2019 13:15:36 +0700, JJ wrote:
>>
>>>>> What do you get if you use curl(1) instead?
>>>>
>>> I am not talking about the PHP support for libcurl, but the original command
>>> line tool:
>>
>> That command line would be errorneous in Windows platform. The whole
>> `curl(1)` would be considered as a filename, and the system will try to
>> search for `curl(1).exe` file. What's that `(1)` supposed to be? It's
>> neither a switch or an URL.
> 
> If I run curl with below command line.
> 
>    curl http://localhost/test.php
> 
> It outputs below error.
> 
>    curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
> 

PMJI, but this typically indicates something happened on the server end. 
  What happens if you try this with a browser?

Also - what do you get if you try it in verbose mode (-v option) of curl?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17946

FromJJ <jj4public@vfemail.net>
Date2019-06-09 08:46 +0700
Message-ID<rws4kue9dew7$.g1s7a3esd9c6$.dlg@40tude.net>
In reply to#17945
On Sat, 8 Jun 2019 11:58:27 -0400, Jerry Stuckle wrote:
> 
> PMJI, but this typically indicates something happened on the server end. 
>   What happens if you try this with a browser?

With Chromium, I got this log in the Console.

  Failed to load resource: net::ERR_INVALID_CHUNKED_ENCODING

With Firefox, I got nothing in the Console. Firefox is bad at this.

Zero byte is received by the browser, according to the Network tab. Yet,
HTTP status code is 200.

> Also - what do you get if you try it in verbose mode (-v option) of curl?

Here's the output. Warning: long text.

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /test.php HTTP/1.1
> Host: localhost
> User-Agent: curl/7.47.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sun, 09 Jun 2019 01:39:25 GMT
< Server: Apache/2.4.38 (Win32) OpenSSL/1.1.1a PHP/7.3.2
< X-Powered-By: PHP/7.3.2
< Expires: Tue, 27 Apr 1971 19:44:06 EST
< X-Frame-Options: SAMEORIGIN
< P3P: CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=id for more info."
< Cache-Control: no-cache
< Strict-Transport-Security: max-age=31536000
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 0
< Set-Cookie: VISITOR_INFO1_LIVE=c4JlmVZxS6c; path=/; domain=.youtube.com; expires=Fri, 06-Dec-2019 01:39:50 GMT; httponly
< Alt-Svc: quic=":443"; ma=2592000; v="46,44,43,39"
< Accept-Ranges: none
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
< 
* Illegal or missing hexadecimal sequence in chunked-encoding
* Closing connection 0
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

[toc] | [prev] | [next] | [standalone]


#17957

FromJerry Stuckle <jstucklex@attglobal.net>
Date2019-06-09 22:10 -0400
Message-ID<qdke7a$rbp$1@jstuckle.eternal-september.org>
In reply to#17946
On 6/8/2019 9:46 PM, JJ wrote:
> On Sat, 8 Jun 2019 11:58:27 -0400, Jerry Stuckle wrote:
>>
>> PMJI, but this typically indicates something happened on the server end.
>>    What happens if you try this with a browser?
> 
> With Chromium, I got this log in the Console.
> 
>    Failed to load resource: net::ERR_INVALID_CHUNKED_ENCODING
> 
> With Firefox, I got nothing in the Console. Firefox is bad at this.
> 
> Zero byte is received by the browser, according to the Network tab. Yet,
> HTTP status code is 200.
> 
>> Also - what do you get if you try it in verbose mode (-v option) of curl?
> 
> Here's the output. Warning: long text.
> 
> *   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 80 (#0)
>> GET /test.php HTTP/1.1
>> Host: localhost
>> User-Agent: curl/7.47.1
>> Accept: */*
>>
> < HTTP/1.1 200 OK
> < Date: Sun, 09 Jun 2019 01:39:25 GMT
> < Server: Apache/2.4.38 (Win32) OpenSSL/1.1.1a PHP/7.3.2
> < X-Powered-By: PHP/7.3.2
> < Expires: Tue, 27 Apr 1971 19:44:06 EST
> < X-Frame-Options: SAMEORIGIN
> < P3P: CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=id for more info."
> < Cache-Control: no-cache
> < Strict-Transport-Security: max-age=31536000
> < X-Content-Type-Options: nosniff
> < X-XSS-Protection: 0
> < Set-Cookie: VISITOR_INFO1_LIVE=c4JlmVZxS6c; path=/; domain=.youtube.com; expires=Fri, 06-Dec-2019 01:39:50 GMT; httponly
> < Alt-Svc: quic=":443"; ma=2592000; v="46,44,43,39"
> < Accept-Ranges: none
> < Vary: Accept-Encoding
> < Transfer-Encoding: chunked
> < Content-Type: text/html; charset=utf-8
> <
> * Illegal or missing hexadecimal sequence in chunked-encoding
> * Closing connection 0
> curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
> 

OK, you're looking at a problem on the server, not in your curl request. 
  If this is your code, you need to look at what the server logs say. 
If this is someone else's code, you need to contact them to find out 
what's going on.

Either way I see no problem with curl right now.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17959

FromJerry Stuckle <jstucklex@attglobal.net>
Date2019-06-09 22:13 -0400
Message-ID<qdkeck$rbp$3@jstuckle.eternal-september.org>
In reply to#17946
On 6/8/2019 9:46 PM, JJ wrote:
> On Sat, 8 Jun 2019 11:58:27 -0400, Jerry Stuckle wrote:
>>
>> PMJI, but this typically indicates something happened on the server end.
>>    What happens if you try this with a browser?
> 
> With Chromium, I got this log in the Console.
> 
>    Failed to load resource: net::ERR_INVALID_CHUNKED_ENCODING
> 
> With Firefox, I got nothing in the Console. Firefox is bad at this.
> 
> Zero byte is received by the browser, according to the Network tab. Yet,
> HTTP status code is 200.
> 
>> Also - what do you get if you try it in verbose mode (-v option) of curl?
> 
> Here's the output. Warning: long text.
> 
> *   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 80 (#0)
>> GET /test.php HTTP/1.1
>> Host: localhost
>> User-Agent: curl/7.47.1
>> Accept: */*
>>
> < HTTP/1.1 200 OK
> < Date: Sun, 09 Jun 2019 01:39:25 GMT
> < Server: Apache/2.4.38 (Win32) OpenSSL/1.1.1a PHP/7.3.2
> < X-Powered-By: PHP/7.3.2
> < Expires: Tue, 27 Apr 1971 19:44:06 EST
> < X-Frame-Options: SAMEORIGIN
> < P3P: CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=id for more info."
> < Cache-Control: no-cache
> < Strict-Transport-Security: max-age=31536000
> < X-Content-Type-Options: nosniff
> < X-XSS-Protection: 0
> < Set-Cookie: VISITOR_INFO1_LIVE=c4JlmVZxS6c; path=/; domain=.youtube.com; expires=Fri, 06-Dec-2019 01:39:50 GMT; httponly
> < Alt-Svc: quic=":443"; ma=2592000; v="46,44,43,39"
> < Accept-Ranges: none
> < Vary: Accept-Encoding
> < Transfer-Encoding: chunked
> < Content-Type: text/html; charset=utf-8
> <
> * Illegal or missing hexadecimal sequence in chunked-encoding
> * Closing connection 0
> curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
> 

I should also note - this might not be a PHP problem.  You need to look 
at your web server's error log as well as any others which might be 
involved (i.e. database, etc.).


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17961

FromJJ <jj4public@vfemail.net>
Date2019-06-10 20:42 +0700
Message-ID<rnhr30dmikij.t51y3b25jnrh.dlg@40tude.net>
In reply to#17959
On Sun, 9 Jun 2019 22:10:49 -0400, Jerry Stuckle wrote:
> 
> OK, you're looking at a problem on the server, not in your curl request. 
>   If this is your code, you need to look at what the server logs say. 
> If this is someone else's code, you need to contact them to find out 
> what's going on.
> 
> Either way I see no problem with curl right now.

On Sun, 9 Jun 2019 22:13:39 -0400, Jerry Stuckle wrote:
> 
> I should also note - this might not be a PHP problem.  You need to look 
> at your web server's error log as well as any others which might be 
> involved (i.e. database, etc.).

Because there's no PHP log about this error, I could not determine whether
it was caused by Curl or PHP side. But if you said curl is not at fault,
then it should the PHP. If the PHP script is at fault, it should either
returns an error, or throw an exception, and at least the fault is logged.
But none of those happens.

[toc] | [prev] | [next] | [standalone]


#17972

FromJerry Stuckle <jstucklex@attglobal.net>
Date2019-06-11 13:15 -0400
Message-ID<qdonjh$cbf$1@jstuckle.eternal-september.org>
In reply to#17961
On 6/10/2019 9:42 AM, JJ wrote:
> On Sun, 9 Jun 2019 22:10:49 -0400, Jerry Stuckle wrote:
>>
>> OK, you're looking at a problem on the server, not in your curl request.
>>    If this is your code, you need to look at what the server logs say.
>> If this is someone else's code, you need to contact them to find out
>> what's going on.
>>
>> Either way I see no problem with curl right now.
> 
> On Sun, 9 Jun 2019 22:13:39 -0400, Jerry Stuckle wrote:
>>
>> I should also note - this might not be a PHP problem.  You need to look
>> at your web server's error log as well as any others which might be
>> involved (i.e. database, etc.).
> 
> Because there's no PHP log about this error, I could not determine whether
> it was caused by Curl or PHP side. But if you said curl is not at fault,
> then it should the PHP. If the PHP script is at fault, it should either
> returns an error, or throw an exception, and at least the fault is logged.
> But none of those happens.
> 

Not necessarily.  Depending on a lot of factors, you may or may not get 
errors logged.

The first thing you need to do is create a .php file with just the code:

<?php phpinfo(); ?>

Put this in your web servers root directory and load it from a browser. 
Things to look for:

In the first block of items, "Loaded Configuration File"  This will be 
the php.ini file you're using.  It may not be the one you think you're 
using.  It may also not be the one your CLI version of PHP is using.

In the Core block, "error_log", "error_reporting" and "log_errors". 
These govern where php errors are logged and what is logged.

What do you have for these values?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17976

FromJJ <jj4public@vfemail.net>
Date2019-06-12 05:51 +0700
Message-ID<87guechjyzad$.1idrjoia13jh4$.dlg@40tude.net>
In reply to#17972
On Tue, 11 Jun 2019 13:15:31 -0400, Jerry Stuckle wrote:
> 
> Not necessarily.  Depending on a lot of factors, you may or may not get 
> errors logged.

Surely you're not saying that it's normal for a script to terminate abruptly
without outputing any error, or are you?

> The first thing you need to do is create a .php file with just the code:
> 
> <?php phpinfo(); ?>

> In the Core block, "error_log", "error_reporting" and "log_errors". 
> These govern where php errors are logged and what is logged.
> 
> What do you have for these values?

It's the same thing as the output of `php -i`.

https://pastebin.com/UykrZrxB

> In the first block of items, "Loaded Configuration File"  This will be 
> the php.ini file you're using.  It may not be the one you think you're 
> using.  It may also not be the one your CLI version of PHP is using.

I'm sure that the `php.ini` I'm using is the correct one, because the first
time I installed XAMPP, I noticed that directory index pages showed
incorrect file/directory modification dates. I found out that the original
`php.ini` uses fixed time zone instead of using OS' time zone, and the time
zone in the `php.ini` wasn't for my location. So I've changed it for my
location, and the change did applied correctly after I checked it from a
directory index page.

[toc] | [prev] | [next] | [standalone]


#17980

FromJerry Stuckle <jstucklex@attglobal.net>
Date2019-06-12 10:37 -0400
Message-ID<qdr2nd$4ks$1@jstuckle.eternal-september.org>
In reply to#17976
On 6/11/2019 6:51 PM, JJ wrote:
> On Tue, 11 Jun 2019 13:15:31 -0400, Jerry Stuckle wrote:
>>
>> Not necessarily.  Depending on a lot of factors, you may or may not get
>> errors logged.
> 
> Surely you're not saying that it's normal for a script to terminate abruptly
> without outputing any error, or are you?
>

Depending on your settings and what the error is, yes.

>> The first thing you need to do is create a .php file with just the code:
>>
>> <?php phpinfo(); ?>
> 
>> In the Core block, "error_log", "error_reporting" and "log_errors".
>> These govern where php errors are logged and what is logged.
>>
>> What do you have for these values?
> 
> It's the same thing as the output of `php -i`.
> 
> https://pastebin.com/UykrZrxB
> 

No, it would NOT be the same as php -i.  You are using two entirely 
different PHP interfaces and can have entirely different values. 
Additionally, your web server version will have setting specific to the 
web server which your CLI does not - and vice versa.

If you're going to use pasebin, how about pasting the output of the web 
version?

>> In the first block of items, "Loaded Configuration File"  This will be
>> the php.ini file you're using.  It may not be the one you think you're
>> using.  It may also not be the one your CLI version of PHP is using.
> 
> I'm sure that the `php.ini` I'm using is the correct one, because the first
> time I installed XAMPP, I noticed that directory index pages showed
> incorrect file/directory modification dates. I found out that the original
> `php.ini` uses fixed time zone instead of using OS' time zone, and the time
> zone in the `php.ini` wasn't for my location. So I've changed it for my
> location, and the change did applied correctly after I checked it from a
> directory index page.
> 

Again, what's in the output of the above?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17983

FromJJ <jj4public@vfemail.net>
Date2019-06-12 22:11 +0700
Message-ID<1c55ks133cv8c$.3glxmc9v1trt$.dlg@40tude.net>
In reply to#17980
On Wed, 12 Jun 2019 10:37:35 -0400, Jerry Stuckle wrote:
> 
> Again, what's in the output of the above?

Here's the output.

https://pastebin.com/bhmJe64Y

[toc] | [prev] | [next] | [standalone]


#17970

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2019-06-11 18:24 +0200
Message-ID<4475263.31r3eYUQgx@PointedEars.de>
In reply to#17946
JJ wrote:

> On Sat, 8 Jun 2019 11:58:27 -0400, Jerry Stuckle wrote:
>> PMJI, but this typically indicates something happened on the server end.
>>   What happens if you try this with a browser?
> 
> With Chromium, I got this log in the Console.
> 
>   Failed to load resource: net::ERR_INVALID_CHUNKED_ENCODING

So it is not a PHP client problem.
 
> With Firefox, I got nothing in the Console. Firefox is bad at this.

No, it just works differently.
 
> Zero byte is received by the browser, according to the Network tab. Yet,
> HTTP status code is 200.

Because that is precisely what the server says:

| HTTP/1.1 200 OK
 
>> Also - what do you get if you try it in verbose mode (-v option) of curl?
> 
> Here's the output. Warning: long text.

If an entire Usenet posting has less than 50 lines, such as yours, it is not 
considered long.

> *   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 80 (#0)
>> GET /test.php HTTP/1.1
>> Host: localhost
>> User-Agent: curl/7.47.1
>> Accept: */*

Please do not use the “>” character at the beginning of a line; it is 
already reserved for indicating quotation levels.  Using it in the wrong 
places confuses software and readers.  For quotations from outside the 
(sub-)thread or where too many quotation levels would have to be reproduced,

  - the leading sequence “| ”
  - indentation or (if that would change the meaning, e.g. with Python)
  - leading and training delimiter lines like “-------- 8< -----------”
    (ASCII art of scissors)

SHOULD be used.

> < Transfer-Encoding: chunked
> < Content-Type: text/html; charset=utf-8
> <
> * Illegal or missing hexadecimal sequence in chunked-encoding
> * Closing connection 0
> curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

Googling for that error message and finding the explanation on
Stack Overflow took me less than 10 seconds (be sure to put error messages 
in quotes when doing a Web search).

It is difficult to believe that PHP’s libcurl support would have no means to 
handle this server bug, but I would have to set up a test case first to be 
sure.  So that’s *your* task, then.

-- 
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]


#17944

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2019-06-08 13:20 +0200
Message-ID<2116427.ElGaqSPkdT@PointedEars.de>
In reply to#17940
JJ wrote:

> On Fri, 07 Jun 2019 15:26:57 +0200, Thomas 'PointedEars' Lahn wrote:
>> What if you increase the log level?
> 
> The default log level is `E_ALL` as specified in the `pnp.ini` file.

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've tried inserting below line at the top of the script, but still no
> error logged.
> 
>   ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_STRICT);

Strange.  Where are errors configured to be logged?
 
>>>> What do you get if you use curl(1) instead?
>> I am not talking about the PHP support for libcurl, but the original
>> command line tool:
> 
> That command line would be errorneous in Windows platform. The whole
> `curl(1)` would be considered as a filename, and the system will try to
> search for `curl(1).exe` 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.

> What's that `(1)` supposed to be? It's neither a switch or an URL.

It is a common unixoid way to designate the number of the section of the 
man(ual) page in which the command/utility in question is being documented.
In this case, section 1, “General/user commands”:

<https://en.wikipedia.org/wiki/Man_page>

As a person developing software using the open-source software PHP, you 
really need to learn about operating systems other than closed-source 
Micro$~1 Windoze[tm].  The majority of (Web) server systems (that use PHP) 
are running a Unix, e.g. GNU/Linux.

<https://en.wikipedia.org/wiki/Usage_share_of_operating_systems#Market_share_by_category>

You are still not posting using your real name.

-- 
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]


#17947

FromJJ <jj4public@vfemail.net>
Date2019-06-09 09:08 +0700
Message-ID<18p8qhdnyktsb$.1jrja9dgo13j6.dlg@40tude.net>
In reply to#17944
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.

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.lang.php


csiph-web