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
391 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
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 …

743 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

10 Experts available now in Live!

Get 1:1 Help Now