Page 1 of 1

Help optimising my curl function

Posted: Tue Jul 24, 2007 2:22 pm
by spamyboy
This is re-writen phpbb class, now I'm trying to optimise it, becouse page load time is more than ~30 sec.
What could I change in code to make it faster.

Code: Select all

Code updated & moved lower

Posted: Tue Jul 24, 2007 2:40 pm
by programmingjeff
Seeing how slow the Warez-BB.org servers are, I'm not sure there's much you can do. You are trying to make 2 connections before your pageload.

If you want to request multiple pages on the website, then you should login once (in order to initiate the cookie). After that, you only need a single CURL call to request subsequent pages.


I would also recommend changing your password. You don't know who has read this thread and may abuse your account.

Posted: Tue Jul 24, 2007 3:05 pm
by spamyboy
Here, I fixed some things.
But still... havent no one got any other sugestions ?

Code: Select all

<?php
class phpbb
{
var $curl=null;
// phpbb function
function phpbb($phpbb_url, $cookie_name = 'tmpfile.tmp')
	{
		if ( empty($phpbb_url) )
		{
			trigger_error('curl_phpbb::error, The phpBB location is required to continue, Please edit your script.');
			return false;
		}
		$this->phpbb_url = $phpbb_url;
		$this->cookie_name = $cookie_name;
}
// end phpbb function

// login function
function login($username, $password)
	{
		global $_SERVER;
		$this->post_fields = $this->array_to_http(array(
			'username'	=> $username,
			'password'	=> $password,
			'autologin'	=> 1,
			'redirect'	=> 'index.php',
			'login'		=> 'Log In',
		));
		$this->open("login.php", TRUE);
		return TRUE;
	}
// end login function

// page open function
function open($phpbb_page, $login)
{
global $_SERVER;
$this->curl = curl_init();
if($login==TRUE) {
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $this->post_fields );
} else {
curl_setopt ( $this->curl, CURLOPT_POST, false );
}
curl_setopt($this->curl, CURLOPT_URL, $this->phpbb_url.$phpbb_page);
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
$result = curl_exec ( $this->curl );
curl_close($this->curl);
return $result;
}
// end - page open function
// array to http function
function array_to_http($array)
	{
		$retvar = '';
		//foreach ($array as $field => $data)
		while ( list ( $field, $data ) = @each ( $array ) )
		{
			$retvar .= ( empty($retvar) ) ? '' : '&';
			$retvar .= urlencode($field) . '=' . urlencode($data); 
		}
		return $retvar;
	}
// and array to http function
}

$phpbb=new phpbb("http://www.example.org/");
$phpbb->login("example", "example");
echo $phpbb->open("index.php", FALSE);
?>

Posted: Tue Jul 24, 2007 3:17 pm
by John Cartwright
I'm not removing your password again..

Posted: Tue Jul 24, 2007 3:20 pm
by spamyboy
Sorry for that :)