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


Groups > de.comp.lang.php > #4158 > unrolled thread

curl Shell-Parameter vs. CURLOPT-Konstanten

Started byRalph Stahl <post@rstahl.de>
First post2017-07-05 13:15 +0200
Last post2017-07-17 20:33 +0200
Articles 9 — 3 participants

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


Contents

  curl Shell-Parameter vs. CURLOPT-Konstanten Ralph Stahl <post@rstahl.de> - 2017-07-05 13:15 +0200
    Re: curl Shell-Parameter vs. CURLOPT-Konstanten Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-06 12:20 +0200
      Re: curl Shell-Parameter vs. CURLOPT-Konstanten Ralph Stahl <post@rstahl.de> - 2017-07-08 22:50 +0200
        Re: curl Shell-Parameter vs. CURLOPT-Konstanten Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-09 05:26 +0200
          Re: curl Shell-Parameter vs. CURLOPT-Konstanten Ralph Stahl <post@rstahl.de> - 2017-07-11 14:21 +0200
            Re: curl Shell-Parameter vs. CURLOPT-Konstanten Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-13 16:00 +0200
              Re: curl Shell-Parameter vs. CURLOPT-Konstanten Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-13 16:37 +0200
                Re: curl Shell-Parameter vs. CURLOPT-Konstanten "Christoph M. Becker" <cmbecker69@arcor.de> - 2017-07-13 18:17 +0200
                  Re: curl Shell-Parameter vs. CURLOPT-Konstanten Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-17 20:33 +0200

#4158 — curl Shell-Parameter vs. CURLOPT-Konstanten

FromRalph Stahl <post@rstahl.de>
Date2017-07-05 13:15 +0200
Subjectcurl Shell-Parameter vs. CURLOPT-Konstanten
Message-ID<ojihhm$pu2$1@dont-email.me>
Moin!

Gibt es irgendwo eine Gegenüberstellung zu lesen, welche Shell-Parameter
von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP entsprechen?

Konkretes Beispiel: Bewirkt -L in der Shell das gleiche wie
CURLOPT_FOLLOWLOCATION in PHP? Ich habe auf der Gegenstelle einen Apache
mit einem 307-Redirect und muss Daten übertragen - ohne -L geht das nicht.

Weder man curl noch http://php.net/manual/de/function.curl-setopt.php
geben darüber Auskunft.

Ralph

[toc] | [next] | [standalone]


#4159

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-07-06 12:20 +0200
Message-ID<1981390.3ZeAukHxDK@PointedEars.de>
In reply to#4158
Ralph Stahl wrote:

> Gibt es irgendwo eine Gegenüberstellung zu lesen, welche Shell-Parameter
> von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP entsprechen?

Ja.
 
> Weder man curl noch http://php.net/manual/de/function.curl-setopt.php
> geben darüber Auskunft.

2 Sekunden googlen nach “curl php command-line options”, 1. Treffer:

<https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl>

Dort

<https://incarnate.github.io/curl-to-php/>

oder

<https://stackoverflow.com/a/1949260/855543>

man curl | less -p --libcurl

(erfordert curl 7.16.1 oder neuer)

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


#4160

FromRalph Stahl <post@rstahl.de>
Date2017-07-08 22:50 +0200
Message-ID<ojrgak$ugn$1@dont-email.me>
In reply to#4159
Thomas 'PointedEars' Lahn schrieb:
> Ralph Stahl wrote:
> 
>> Gibt es irgendwo eine Gegenüberstellung zu lesen, welche Shell-Parameter
>> von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP entsprechen?
> 
> Ja.
>  
>> Weder man curl noch http://php.net/manual/de/function.curl-setopt.php
>> geben darüber Auskunft.
> 
> 2 Sekunden googlen nach “curl php command-line options”, 1. Treffer:
> 
> <https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl>
> 
> Dort
> 
> <https://incarnate.github.io/curl-to-php/>
> 
> oder
> 
> <https://stackoverflow.com/a/1949260/855543>
> 
> man curl | less -p --libcurl
> 
> (erfordert curl 7.16.1 oder neuer)
> 

Danke dass du für mich Frau Google befragt hast ;-). Wenn man weiß,
wonach man fragen muss, ist es wirklich leicht - ich wusste es eben nicht...

Ralph

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


#4161

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-07-09 05:26 +0200
Message-ID<2386485.mvXUDI8C0e@PointedEars.de>
In reply to#4160
Ralph Stahl wrote:

> Thomas 'PointedEars' Lahn schrieb:
>> Ralph Stahl wrote:
>>> Gibt es irgendwo eine Gegenüberstellung zu lesen, welche Shell-Parameter
                                                             ^^^^^^^^^^^^^^^
>>> von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP
        ^^^^         ^^^                      ^^^^^^^^
>>> entsprechen?
>> 
>> […]
>>> Weder man curl noch http://php.net/manual/de/function.curl-setopt.php
>>> geben darüber Auskunft.
>> 
>> 2 Sekunden googlen nach “curl php command-line options”, 1. Treffer:
>> 
>> <https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl>
>> […]
> 
> Danke dass du für mich Frau Google befragt hast ;-). Wenn man weiß,
> wonach man fragen muss, ist es wirklich leicht - ich wusste es eben
> nicht...

Du musst jetzt ganz tapfer sein:

<https://www.google.ch/search?q=Shell-Parameter+curl+PHP+CURLOPT_>

im Inkognito-Fenster (also unabhängig von meinem Google-Konto) liefert 
obigen URI als ersten Treffer.

Bei

<https://www.google.com/search?q=Shell-Parameter+curl+PHP+CURLOPT_>

ist es der dritte und bei

<https://www.google.de/search?q=Shell-Parameter+curl+PHP+CURLOPT_>

der vierte.

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


#4162

FromRalph Stahl <post@rstahl.de>
Date2017-07-11 14:21 +0200
Message-ID<ok2fkb$jao$1@dont-email.me>
In reply to#4161
Thomas 'PointedEars' Lahn schrieb:
> Ralph Stahl wrote:
> 
>> Thomas 'PointedEars' Lahn schrieb:
>>> Ralph Stahl wrote:
>>>> Gibt es irgendwo eine Gegenüberstellung zu lesen, welche Shell-Parameter
>                                                              ^^^^^^^^^^^^^^^
>>>> von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP
>         ^^^^         ^^^                      ^^^^^^^^
>>>> entsprechen?
>>>
>>> […]
>>>> Weder man curl noch http://php.net/manual/de/function.curl-setopt.php
>>>> geben darüber Auskunft.
>>>
>>> 2 Sekunden googlen nach “curl php command-line options”, 1. Treffer:
>>>
>>> <https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl>
>>> […]
>>
>> Danke dass du für mich Frau Google befragt hast ;-). Wenn man weiß,
>> wonach man fragen muss, ist es wirklich leicht - ich wusste es eben
>> nicht...
> 
> Du musst jetzt ganz tapfer sein:
> 
> <https://www.google.ch/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
> 
> im Inkognito-Fenster (also unabhängig von meinem Google-Konto) liefert 
> obigen URI als ersten Treffer.
> 
> Bei
> 
> <https://www.google.com/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
> 
> ist es der dritte und bei
> 
> <https://www.google.de/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
> 
> der vierte.
> 

Sehr schön. Nur, den von gesuchten Parameter-Ersatz für -L (das hatte
ich allerdings nicht erwähnt, sorry), nämlich CURLOPT_FOLLOWLOCATION,
hat keine dieser Quellen zutage gefördert, auch nicht der genannte
Konverter - ist also alles nicht vollständig. Die Frage an Google nach
"php curl redirect" allerdings schon.

Nichts für ungut,

$c = curl_init();
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);

ist die gesuchte Lösung als Ersatz für -L.

Ralph

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


#4163

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-07-13 16:00 +0200
Message-ID<2392003.mvXUDI8C0e@PointedEars.de>
In reply to#4162
Ralph Stahl wrote:

> Thomas 'PointedEars' Lahn schrieb:
>> Ralph Stahl wrote:
>>> Thomas 'PointedEars' Lahn schrieb:
>>>> Ralph Stahl wrote:
>>>>> Gibt es irgendwo eine Gegenüberstellung zu lesen, welche
>>>>> Shell-Parameter
>>                                                              
^^^^^^^^^^^^^^^
>>>>> von curl welchen PHP-Optionen (Konstanten CURLOPT_...) in PHP
>>         ^^^^         ^^^                      ^^^^^^^^
>>>>> entsprechen?
>>>>
>>>> […]
>>> Danke dass du für mich Frau Google befragt hast ;-). Wenn man weiß,
>>> wonach man fragen muss, ist es wirklich leicht - ich wusste es eben
>>> nicht...
>> 
>> Du musst jetzt ganz tapfer sein:
>> 
>> <https://www.google.ch/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
>> 
>> im Inkognito-Fenster (also unabhängig von meinem Google-Konto) liefert
>> obigen URI als ersten Treffer.
>> 
>> Bei
>> 
>> <https://www.google.com/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
>> 
>> ist es der dritte und bei
>> 
>> <https://www.google.de/search?q=Shell-Parameter+curl+PHP+CURLOPT_>
>> 
>> der vierte.
>> 
> 
> Sehr schön. Nur, den von gesuchten Parameter-Ersatz für -L (das hatte
> ich allerdings nicht erwähnt, sorry),

Du hattest es erwähnt.

> nämlich CURLOPT_FOLLOWLOCATION, hat keine dieser Quellen zutage gefördert,
> […]

| $ curl -L foo --libcurl -
| […]
| curl: (6) Could not resolve host: foo
| /********* Sample code generated by the curl command line tool **********
|  * All curl_easy_setopt() options are documented at:
|  * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
|  ************************************************************************/
| #include <curl/curl.h>
| 
| int main(int argc, char *argv[])
| {
|   CURLcode ret;
|   CURL *hnd;
| 
|   hnd = curl_easy_init();
|   curl_easy_setopt(hnd, CURLOPT_URL, "foo");
|   curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
|   curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|   […]
| }
| /**** End of sample code ****/
| 
| $ curl --version
| curl 7.50.1 (x86_64-pc-linux-gnu) libcurl/7.50.1 GnuTLS/3.5.3 zlib/1.2.8 
| libidn/1.33 libssh2/1.7.0 nghttp2/1.14.0 librtmp/2.3
| Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 
| pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
| Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM 
| NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets

> auch nicht der genannte Konverter - ist also alles nicht vollständig.

Das steht ja auch da.  Man sollte[tm] wohl besser einen Konverter schreiben, 
der “curl --libcurl -” verwendet und das Ergebnis von C nach PHP 
konvertiert.  Im Prinzip braucht man dafür nur ein paar reguläre Ausdrücke.

> Die Frage an Google nach "php curl redirect" allerdings schon.

Kommt darauf an.
 
> Nichts für ungut,
> 
> $c = curl_init();
> curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
> 
> ist die gesuchte Lösung als Ersatz für -L.

Richtig.

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


#4164

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-07-13 16:37 +0200
Message-ID<10876584.O9o76ZdvQC@PointedEars.de>
In reply to#4163
Thomas 'PointedEars' Lahn wrote:

> […]  Man sollte[tm] wohl besser einen Konverter schreiben, der
> “curl -- libcurl -” verwendet und das Ergebnis von C nach PHP konvertiert.  
> Im Prinzip braucht man dafür nur ein paar reguläre Ausdrücke.

Quickhack mit GNU sed:

#--------------------------------------------------------------------------
curl -L foo --libcurl - |
sed '
  1,/curl_easy_init/d;
  s/^\([[:space:]]*\)curl_easy_setopt(\([^,]\+\), CURLOPT_URL, \("[^"]\+"\));/<?php\n\1$\2 = curl_init(\3);/;
  s/curl_easy_/curl_/g;
  s/\(curl_setopt(\)\([^,]\+\)/\1$\2/;
  s/\(, [0-9]\+\)L/\1/; s/, ([^)]\+)/, /;
  s/^\([[:space:]]*\)\([0-9a-zA-Z]\+\)[[:space:]]*=[[:space:]]*\(.\+\)/\1$\2 = \3/;
  s/curl_perform(/curl_exec($/;
  s/curl_cleanup(/curl_close($/;
  /return/,$d
' |
php -d error_reporting=E_ALL
#--------------------------------------------------------------------------

compiliert.

Die Konstante CURL_HTTP_VERSION_2TLS gibt es in PHP-curl nicht;
die entsprechende Zeile lässt man dann einfach weg, da PHP-curl
automatisch die richtige (sicherste) Protokollversion auswählt.
Andernfalls erhält man eine PHP-Warnung (ausser man setzt
error_reporting entsprechend).

> >> Die Frage an Google nach "php curl redirect" allerdings schon.
> 
> Kommt darauf an.
>  
>> Nichts für ungut,

Alles wird gut :)

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


#4165

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2017-07-13 18:17 +0200
Message-ID<ok86fl$1ge$1@solani.org>
In reply to#4164
Am 13.07.2017 um 16:37 schrieb Thomas 'PointedEars' Lahn:

> Die Konstante CURL_HTTP_VERSION_2TLS gibt es in PHP-curl nicht;

Doch:
<https://github.com/php/php-src/blob/04fb3f28ff677d036cfaf902f07b75f0346a5c33/ext/curl/interface.c#L1349>.
 Ist eventuell aber nicht dokumentiert?

-- 
Christoph M. Becker

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


#4166

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-07-17 20:33 +0200
Message-ID<5288918.lOV4Wx5bFT@PointedEars.de>
In reply to#4165
Christoph M. Becker wrote:

> Am 13.07.2017 um 16:37 schrieb Thomas 'PointedEars' Lahn:
>> Die Konstante CURL_HTTP_VERSION_2TLS gibt es in PHP-curl nicht;
> 
> Doch:

Jein.

> <https://github.com/php/php-src/blob/04fb3f28ff677d036cfaf902f07b75f0346a5c33/ext/curl/interface.c#L1349>.

Das ist *C*-Code von PHP *7.x* oder neuer.

>  Ist eventuell aber nicht dokumentiert?

Wie man im C-Code sieht, hängt die Verfügbarkeit der Konstante in PHP neben 
der PHP-Version auch von der Version der libcurl ab, mit der PHP compiliert 
wurde.  Sofern die verwendete Version der libcurl 7.47.0 oder neuer war, so 
ist die Konstante ab PHP 7.0 verfügbar.

<https://github.com/php/php-src/blob/PHP-5.6.31/ext/curl/interface.c#L853-L859>

| $ curl -L foo --libcurl - | sed '1,/curl_easy_init/d; 
s/^\([[:space:]]*\)curl_easy_setopt(\([^,]\+\), CURLOPT_URL, 
\("[^"]\+"\));/<?php\n\1$\2 = curl_init(\3);/; s/curl_easy/curl/g; 
s/\(curl_setopt(\)\([^,]\+\)/\1$\2/; s/\(, [0-9]\+\)L/\1/; s/, ([^)]\+)/, /; 
s/^\([[:space:]]*\)\([0-9a-zA-Z]\+\)[[:space:]]*=[[:space:]]*\(.\+\)/\1$\2 = 
\3/; s/curl_perform(/curl_exec($/; s/curl_cleanup(/curl_close($/; /return/,
$d' | php
|   % Total    % Received % Xferd  Average Speed   Time    Time     Time  
Current
|                                  Dload  Upload   Total   Spent    Left  
Speed
|   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     
0curl: (6) Could not resolve host: foo
| PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
| PHP Warning:  Module 'vld' already loaded in Unknown on line 0
| PHP Notice:  Use of undefined constant CURL_HTTP_VERSION_2TLS - assumed
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| 'CURL_HTTP_VERSION_2TLS' in - on line 6
| PHP Stack trace:
| PHP   1. {main}() -:0
| 
| $ php --version
| PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
| PHP Warning:  Module 'vld' already loaded in Unknown on line 0
| PHP 5.6.30-0+deb8u1 (cli) (built: Feb  8 2017 08:50:21) 
| Copyright (c) 1997-2016 The PHP Group
| Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
|     with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend 
Technologies
|     with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
 
-- 
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] | [standalone]


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


csiph-web