File: index_2.php

Recommend this page to a friend!
  Classes of riccardo castagna  >  Fast PHP CURL Multiple Requests  >  index_2.php  >  Download  
File: index_2.php
Role: Example script
Content type: text/plain
Description: EXAMPLE FILE
Class: Fast PHP CURL Multiple Requests
Retrieve the content of multiple URLs using CURL
Author: By
Last change: I added some useful resources about the rest api's in the comments, and I added a new file with another useful example, view file: index_3.php
Date: 3 years ago
Size: 2,951 bytes


Class file image Download
In this example I have used the open data OF public transport of Palermo city:
available under the license:,
and the technical documentation of APIs in real time of the public road
transport service in Palermo:
it shows how php curl multi work with a rest api.
In this example with the method GetStopArrivals of moovitapp REST API,
it return 3 json because I did 3 simultaneous asynchronous calls with CURL POST protocol for the
bus stops number 1258, 1259, 1260.
The data are in real time, so in you make a page refresh you will see the data changed; the data will show for
each bus stop the arrivals time of the buses.
After the 22.00 (10.00 P.M.) you will see no data because there are no buses in circulation in Palermo
city after the 22.00 o'clock.
This is only a sample to show all the power of the php_curl_multi with a rest api from which you can take a cue.

Sometimes this example response with internal server error due to many requests.

For demonstration purposes I have published an other example, view file index_3.php with the
API's that uses the GET method and retuns a json.
There's plenty of things you can do with rest API's, you're spoiled for choice:
some others useful resources here: ,
enjoy oneself
$ref= new cURmultiStable;

$urllinkarray = array('',

$postfield = array("{\n\t\"stopKey\": \"1258\"\n}", "{\n\t\"stopKey\": \"1259\"\n}", "{\n\t\"stopKey\": \"1260\"\n}");

$headers = array(array("api_key: amat_palermo_2317885288","content-type: application/json","user_loc: (38.115093,13.356520)"),
"api_key: amat_palermo_2317885288","content-type: application/json","user_loc: (38.115093,13.356520)"),
"api_key: amat_palermo_2317885288","content-type: application/json","user_loc: (38.115093,13.356520)"));

$urls = $ref->multicurlRestApi($urllinkarray, $postfield, $headers);


For more information send a message to info at phpclasses dot org.