NETCURLv6.0

NETCURLv6.0

Other documents

Exceptions handling

Compatibility span (Supported PHP versions)

This library should be compatible with at least PHP 5.3 up to PHP 7.2. However, running this module in older versions of PHP makes it more unreliable as PHP is continuosly developed. There are no guarantees that the module is fully functional from obsolete releases (like PHP 5.3 and most of the PHP 5.x-series is).

Requirements and dependencies

Some kind of a supported driver is needed. NetCURL was built for curl so it could be a great idea to have curl available in your system. The goal with the module is however to pick up the best available driver in your system.

Supported drivers

  • curl

  • soap (SoapClient with XML)

  • Guzzle

  • Wordpress 

Future plans for independence:

  • Streams

  • Sockets

Dependencies and installation

As netcurl is built to be independently running dependencies is not necessesary required. To reach full functionality the list below might be good to have available.

  • Installation: Composer. NetCURL can be bundled/manually downloaded, but the best practice is to install via composer. Otherwise you're a bit on your own.

  • SSL (OpenSSL): Not having SSL available means that you won't be able to speak https

  • SOAP: To make use of the SOAP components in NetCurl, XML libraries and SoapClient needs to be there. SoapClient uses Streams to fetch wsdl.

XML, CURL, SOAP

In apt-based systems, extra libraries can be installed with commands such as:

 

apt-get install php-curl php-xml php-soap

 

The module installation itself

This is the recommended way (and only officially supported) of installing the package.

1. Get composer.
2. Run composer:

composer require tornevall/tornelib-php-netcurl

Composer also adds the crypto module during the installation. API-docs can be found here, as this site is not yet updated with this.

NetCurl Parsing

  • By PHP serialized content (serialize/unserialize)

  • JSON

  • XML (Starting with SimpleXMLElements, the PEAR/PECL modules such as XmlSerializer/XMLUnserializer are also supported)

  • DOMDocument (Converts html documents into DOMDocument arrays, by three methods: nodesclosest tags and element ids)

NetCurl extra features

The name NetCurl was born from the fact that there are more than one module in this class file. A network module also resides in the single file, which is the primary reason why it is called NetCurl. NetCurl takes care of different network based features, like resolving hosts, making sure that ip-addresses is really ip-addresses, extracts proxy addresses from server variables, encodes base64-strings into URL-compatible strings, reads CIDR-formatted netmasks properly, etc, etc, etc. This part of the documentation has documentation of all those modules.

Internal drivers

Driver

Class

Provides

Installation

Notes

Driver

Class

Provides

Installation

Notes

CURL

MODULE_CURL

curl

Curl must be installed

 

SimpleSoap

MODULE_SOAP

SoapClient
(Streams)

 

 

Importable drivers

NetCurl primarily supports curl, as the name reveals. However, if you run wordpress or Guzzle, there is a small driver switch in NetCurl that makes it possible to survive without curl. Below, the supported drivers are listed and what they may provide for you.

Driver

Class

Provides

Installation

Notes

Wordpress

WP_HTTP

curl and streams

WP must be present

On SOAP, SoapClient makes fallback to internal class

GuzzleHttp

GuzzleHttp\Client
GuzzleHttp\Handler\StreamHandler 

curl and streams

Add to composer.json:

"guzzlehttp/guzzle": "6.3.0"

On SOAP, SoapClient makes fallback to internal class

Driver overriders

Overriding the default drivers can be done by running for example.

Say that you'd prefer to use Guzzle over CURL. First of all, this is kind of double building the network module as guzzle primarily uses CURL to run. So doing this will make you build a wrapper over a wrapper, instead of going directly through curl.

First of all, you need to get the guzzle package. This is done by adding this row into your composer.json-file (or use the composer require statement).

"guzzlehttp/guzzle": "^6.3"

When this is done, use composer install or composer update and start adding your code:

$CURL = new MODULE_CURL(); $CURL->setDriver(NETCURL_NETWORK_DRIVERS::DRIVER_GUZZLEHTTP); // or $CURL->setDriver(NETCURL_NETWORK_DRIVERS::DRIVER_GUZZLEHTTP_STREAM);

The best available driver could also be autodetected via the method setDriverAuto().