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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.