Using the curl function is slowing my app down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
burnside
Forum Newbie
Posts: 8
Joined: Tue May 05, 2009 11:38 pm

Using the curl function is slowing my app down

Post by burnside »

Hi,

I have a php phone app (click to call sort of thing) I'm writing that sends data filled in via a form and sends it to another server which places the phone call. The phone server api suggests to use the curl function to send the url with the data appended in the query string. That's fine and all, but when I use curl to send that url, my submission page hangs until the call connects. So in other words, here is the process:

1. Form page -> 2. Page where I do validation and initiate the curl -> 3. Success page shown to person who filled the form

To get around the problem I encountered with waiting for the call to connect, I created a new page with the curl function. Then in step 2, I use the fsockopen to process that new page. Now the form user gets right to the submission page quickly since the curl process is carried out in the background.

So my question? Is this the right way to be doing things? Is there a better way and maybe better yet, is this secure?

Thanks!
b
david64
Forum Commoner
Posts: 53
Joined: Sat May 02, 2009 8:12 am
Location: Wales

Re: Using the curl function is slowing my app down

Post by david64 »

Don't really know what you are doing here. There are some timeout options here that might help:

http://uk.php.net/manual/en/function.curl-setopt.php

Additionally, I have made an OO cURL class that might help you.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Using the curl function is slowing my app down

Post by John Cartwright »

PHP is probably not the best tool for this. As you have managed to discover, expensive operations are better handled in the background by a daemon. I would either suggest a cron job to pick up pending tasks if the operation is not time critical, or implement some sort of multi-threaded application residing on the server to accept requests on the go.

Reguardless, depending how important this is to you, your current implementation should be ok. I just wouldn't expect it to scale very well.
burnside
Forum Newbie
Posts: 8
Joined: Tue May 05, 2009 11:38 pm

Re: Using the curl function is slowing my app down

Post by burnside »

Thanks for your answers guys. I'll look into deploying a cron job.
Post Reply