Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php api include simplexml timeout

Status
Not open for further replies.

mwpclark

Programmer
Mar 14, 2005
59
US
I am looking for architecture suggestions. I have many different domains that use php to include an api call to a third party server. The results are xml and I use simplexml to parse the results.

Generally the third party api is very good. Sometimes, however, it is slow and causes pages not to load. Once it broke and I had thousands of pages not loading until the api was fixed.

I have been trying to eliminate http calls, so I am defining variables first, then including the script with simplexml. Everything I have read says there is no timeout function with simplexml.

The alternative would be to use file_get_contents, and throw a timeout in there somewhere. But this gets back to using http and the GET variable to define the variables, which results in many thousands of http calls.

Is there a simple way around this? That is, a way to generate and parse the xml, insert a timeout so the page load will not hang, and make the calls through the directory structure rather than http?

Thanks in advance for any tips!

Mike
 
We eliminate the third party server dependency by running cron jobs to store/update the data into a database. Then all of our web pages for our website simply pull from the database. If the API goes down, no problem, it uses the most up-to-date data stored in the database. Pretty common practice I would think.

Creator of - Movie Reviews, Movie Lists, and much more!
 
Thanks barryna, we did this for a while, but on conferring with the the api provider, learned they put time codes and session id's into individual links, so they must be grabbed in real-time in order to credit us for the traffic. This is a jobs display program that is paying fairly well, so we are living with the issues and hoping they don't crash again!
 
i don't see how you use simplexml to GET the traffic.
normally you would create your outbound messages and bung them into the API via a soap client or using curl. then capture the response and parse it. with soap and curl you can absolutely set a timeout parameter.

simplexml has no method of getting remote data (other than the load file function with a remote wrapper, which I would not advise).

I would take the revenue hit and use cached data for a period of time until the server came back on line. It is better, one would think, to show your users something rather than a broken link.

Create an alert to inform decision makers if the outage continues past, say, one hour.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top