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
401 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
  • 4
  • 2
7 Comments
 
LVL 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now