Solved

I am making a PHP script that sends a file to another server to process, the process takes 5-8 secs. Should I use CURL to upload and wait for reply, or use AJAX call to check every second for update?

Posted on 2011-09-10
7
423 Views
Last Modified: 2012-05-12
Hi,

I am making a PHP script that sends a file to another server to process, the process of the file takes 5 to 8 seconds. Should I use CURL to upload and wait for reply, or upload it and use AJAX call to check every second for an update?

I am not sure which approach is better for the servers performances, we send a lot of files every second. I am afraid at some point it gets congested.

Any ideas/tips?

Thank you.
0
Comment
Question by:Octalys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36517735
Why does the other server take so long to process the file?  Where is the bottleneck?
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 36517765
I would use ajax, but I wouldn't check every second for a response, I would just use a callback with a reasonable timeout. While it's processing, just display one of those spinny animated gifs so that it looks like it's doing something.

0
 

Author Comment

by:Octalys
ID: 36517775
Hi,

Ray_Paseur, we have to analyse the file and do something with it. Sadly the process takes about 5 secs, its not something we will improve soon.

We will using extra servers for analysing to balance the load. But what I am wondering is, what is the best approach for the web servers. Wait with after CURL or AJAX calls? Or perhaps something else?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Octalys
ID: 36517785
We did use AJAX calls before with another different project that does the same, but the process took like 5 seconds to a few minutes to complete.

But we didnt have to send files every second, so it wasnt that bad. But once awhile due external problem. It gets too congested and the AJAX calls were killing the servers!
0
 

Author Comment

by:Octalys
ID: 36517793
Oyeah and the files and user submitted, so we cant really stop the process of incoming files.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36518662
You can go two different ways with CURL.  You can do a GET request, which is synchronous.  Your CURL-GET script can wait until the process is finished and the remote server responds, or it can timeout (There are lots of CURL options).  You can do a POST request which is asynchronous.  Your CURL-POST script can start the process on the remote server and then keep right on doing other things while the remote server works.  This is similar to starting a remote script with fSockOpen().

Not sure if this would be useful to you because I do not know enough about the nature of the application or the required client experience, but I will suggest it anyway.  Let's call our servers "home" and "away."  Each server can have asynchronous processes running.  When the home server wants to make a request to the away server, it will log the request in a data base, and use a RESTful interface to call the away server.  The home server will pass the data base key along with the request.  The away server will process the request and when it is complete it will make a RESTful request to the home server, returning the response and the data base key.  When the home server receives the response, it can use the returned key to go into the data base and mark the request complete.  This kind of design will give you the maximum independence between the servers and allow for load balancing.
0
 

Author Closing Comment

by:Octalys
ID: 36527495
I have been thinking myself after posting this question, and my conclusion is the same as you suggested.

Thank you for your answers!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question