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
428 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
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.

728 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