Page 1 of 1

Using the curl function is slowing my app down

Posted: Wed May 06, 2009 12:01 am
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

Re: Using the curl function is slowing my app down

Posted: Wed May 06, 2009 4:04 pm
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.

Re: Using the curl function is slowing my app down

Posted: Wed May 06, 2009 5:28 pm
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.

Re: Using the curl function is slowing my app down

Posted: Wed May 13, 2009 11:46 pm
by burnside
Thanks for your answers guys. I'll look into deploying a cron job.