简体   繁体   中英

How to get data from another server using - php

The title of this question doesn't explain clearly what I'm looking for, but my question below does. So please read and if possible give me a better solution.

What I'm Developing: I'm developing an IMS (Inquiry Management System) application using Codeignitor.

What exactly IMS does: It collects user submitted data from different website and displays it on the IMS personalized account system.

Where I'm stuck: There are so many method to collect data from an other server, it can be a direct post method to the IMS server or the IMS reads json/xml based data from the source server to fetch data etc. But my question here is how can i get 100% data from the source without loosing any user submits?

100% what i mean is...

Like: If I'm using a direct post method to collect data from source server:-

*What if the IMS server is down when the user submitting the data from source server?

Like: If I'm using json or XML method to fetch data from the source server:-

*I might have to create db on each server for this to work, so an API based solution will be a complete flop.

I hope my question is clear.

Please let me know what is the alternative and best solution for the above mentioned scenario.

Regards Fahid

You can use curl to scrape data from websites. You may also need a domparser to read the content

Example What is cURL in PHP?

if you already know what urls you are using to get the data from, could you use a database on the application side to store urls and relate what method to use to retrieve the data? that way you can create a model and each method would be its own function. example $this->model->xml() or $this->model->post etc.

use API's to fetch data from another server with using urls.

// From URL to get webpage contents.
$url = "https://www.wel.org/";
 
// Initialize a CURL session.
$ch = curl_init();
 
// Return Page contents.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
//grab URL and pass it to the variable.
curl_setopt($ch, CURLOPT_URL, $url);
 
$result = curl_exec($ch);
 
echo $result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM