Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts

    am I using cURL right here?

    Hi guys

    It takes 16 secs to perform this hahhaa so I guess i'm doing something wrong??

    I'm doing this all in one script btw;

    I use curl to log in and get a session --- then I use curl to post back with the session to an API to get the data I want.

    It works, but am I using curl correctly here?


    This is what I am doing in PHP:

    Start curl to go get session data

    PHP Code:
    $ch curl_init(); 
    curl_setopt ($chCURLOPT_URL$url); 
    curl_setopt ($chCURLOPT_SSL_VERIFYPEERtrue);
    curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
    curl_setopt ($chCURLOPT_TIMEOUT60); 
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
    curl_setopt ($chCURLOPT_REFERER$url); 
    curl_setopt ($chCURLOPT_POST1); 
    curl_setopt ($chCURLOPT_POSTFIELDS$postdata); 


    Here I get the session data
    so I close curl

    curl_close
    ($ch); 

    start curl again, this time posting back with session to get the data I want

    PHP Code:
    $ch curl_init(); 
    curl_setopt ($chCURLOPT_URL$url); 
    curl_setopt ($chCURLOPT_SSL_VERIFYPEERtrue);
    curl_setopt ($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
    curl_setopt ($chCURLOPT_TIMEOUT60); 
    curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
    curl_setopt ($chCURLOPT_REFERER$url); 
    curl_setopt ($chCURLOPT_POST1); 
    curl_setopt ($chCURLOPT_POSTFIELDS$postdata); 


    Here I get the data I want

    and close again

    curl_close
    ($ch); 
    I use data here

    round trip 16 secs I can't be right

    LT
    Last edited by low tech; 07-08-2013 at 10:06 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,310
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Dude enough of the hahaha'ing... it's code.. whats funny about it?

    Only thing I'll suggest is that you don't bother closing curl between requests. Just change the parameters and then trigger it again using exec()

    Love your sig btw.. what you can do for others is use the [php] tags in your future posts
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    tangoforce
    Dude enough of the hahaha'ing... it's code.. whats funny about it?
    It was funny to me because I thought 16 secs seemed a long time considering how fast the net is generally, but point taken and post edited.

    Thanks

    LT (not Dude)
    Last edited by low tech; 07-08-2013 at 11:49 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,310
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Unfortunately code will take as long as it takes. Given that you've only shown a few lines of curl code and comments in between rather than pasting the entire affected code there isn't anything that any of us can suggest really other than not closing the curl handle between them.

    Give that a go, if it works thats your problem. If it doesn't you'll need to post your code AS-IS without showing us your 'selected' lines.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •