Jump to content

How not to repeat this whole script (curl)


kutchbhi

Recommended Posts

I have simple script here that uses curl to post to a few forms and send receive cookies.

Now whenever I run the script it takes 10 seconds for the whole process to finish . Is it possible to reduce this time whenever the script is run the second or third.. time. 

my english is poor , i am having difficulty in putting words to what I want to say... But what I want is for the script to somehow use the previous cookies , detect if they are expired and then do things accordingly(run only the last block of code , if cookie hasn't expired) .

 

How do I go about doing this ? any suggestions ?

 

Thanks

The script:

<?php

//Create File
// $ckfile = tempnam("","testfile.tmp") ;
$ckfile = "testFile.tmp";
$ourFileHandle = fopen($ckfile, 'w') or die("can't open file");
fclose($ourFileHandle); 


//goto home page , to get initial cookies (not required the second time)
$ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/falcon.application_start");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

////click on enter as guest. and post the info from te form.
$ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon_Users_Cookies.Run_Create");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "p_JS=N&p_Anon=ANONYMOUS&p_user_type=Enter as Guest");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

//open the search page. 
$ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon.Search_Screen?p_search_no=0&p_SearchLevel=FULL");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);

curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

//search on the search page.
$ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon.Result");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);

curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "p_partword_1=nice");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_exec ($ch);

//fclose($ourFileHandle); 


?>

 

Also for some reason the cookie file ends up being a zero byte file. any one know why

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.