w
Table of Contents |
---|
I can't run this on PHP 5.3 or PHP 5.4 or ...
...
In version 6.0.20 a self adjusting feature was added to handle verification errors automatically. Especially the error codes 14090086 (routines:ssl3_get_server_certificate:certificate) and 1407E086 (routines:SSL2_SET_CERTIFICATE) was added to the core to make sure - if it was allowed by the system - such problems could be bypassed. By means, in this case it is equal to a security layer removal (by simply disable SSL verifications on fly).
...
Most of the options available in curl is configurable, by the WrapperConfig-class, except for the settings below (not getCurlHandle included).
curlopt | static value | notes |
---|---|---|
CURLOPT_URL | User defined url. | Legacy for fetching an URL, that potentially makes it possible to fetch an URL from a server that is normally not the one pointed out in DNS entries. In the initial releases of netcurl 6.0 the url was called directly from the execution parts. |
CURLOPT_HEADER | false | |
CURLOPT_RETURNTRANSFER | true | |
CURLOPT_AUTOREFERER | true | |
CURLINFO_HEADER_OUT | true | |
CURLOPT_HEADERFUNCTION | Internal getCurlHeaderRow. |
...
Code Block | ||||
---|---|---|---|---|
| ||||
$wrapper = (new NetWrapper())->request(['https://test.com']); $wrapper->getBody('https://test.com'); $wrapper->getParsed('https://test.com'); |
Different exception executions
Exceptions are also handled differently for multiple calls. The default behaviour is to throw all exceptions when all requests are fulfilled. This happens since the entire process should be protected and not fail, due to only one request.
When exceptions are thrown there are two ways of getting the failed errors.
If you wrapped the request in a online request like this ...
...
PHP 8.0 Updates
As of PHP 8.0 the curl driver is no longer declared as as resource but a class. Netcurl takes care of this and with netcurl 6.1.2, the internal driver also drops the strict resource checking. To force strict checks, which practically means that netcurl will verify whether the initalized curl driver is really either an object (the class) or a resource (< PHP 8), you can do this as follows:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| try {
| |||||||
use TorneLIB\Config\Flag;
Flag::setFlag('strict_resource', false); |
Different exception executions
Exceptions are also handled differently for multiple calls. The default behaviour is to throw all exceptions when all requests are fulfilled. This happens since the entire process should be protected and not fail, due to only one request.
When exceptions are thrown there are two ways of getting the failed errors.
If you wrapped the request in a online request like this ...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
try {
(new NetWrapper())->request(
[
'http://ipv4.netcurl.org/http.php?code=200&message=Funktionsduglig',
'http://ipv4.netcurl.org/http.php?code=500&message=Kass',
'http://ipv4.netcurl.org/http.php?code=500&message=Trasig',
'http://ipv4.netcurl.org/http.php?code=201&message=Mittemellan',
]
);
} |
...
By catching ExceptionHandler instead of a regular Exception, you can fetch the currently used wrapper by getExtendException(). In this case, that variable contains the CurlWrapper object, from which you can continue get parsed data. The way exceptions are handled here is the same for simple requests. The second way, if you need to keep the wrapper intact regardless of exceptions this works aswell:
...
language | php |
---|---|
theme | Emacs |
title | genericTest.php -- regularExceptionTest |
works aswell:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$wrapper = new NetWrapper(); try { $wrapper->request('http://ipv4.netcurl.org/http.php?code=404&message=Error404+Generated'); } catch (ExceptionHandler $e) { $wrapper$code = new NetWrapper$e->getCode(); try} { $reqCode = $wrapper->request('http://ipv4.netcurl.org/http.php?code=404&message=Error404+Generated'); } catch (ExceptionHandler $e) { $code = $e->getCode(); } $reqCode = $wrapper->getCode();>getCode(); |
Custom headers
As of v6.1.2, a patch has been added to keep custom headers intact. The curlwrapper usually resets all content each "round" it is running, so the modules does not have to be reinstantiated for each new call. By means, this also resets custom headers. A problem was discovered with the cachet Statuspage where authentication tokens was reset each time the monitoring script used to update components. For 6.1.2 this is fixed in the setCurlHeader() method with a third argument, that sets the specific header to a static. So each time the scripts are running, all static headers will stay put despite the reset.
The same with static custom headers are also patched into NetWrapper and the simple streamwrapper, so as of 6.1.2 setHeader() as been added to the CurlWrapper, SimpleStreamWrapper and NetWrapper to keep the calls generic.