Location: PHPKode > scripts > Fast Curl > fast-curl/test.php
<?php

/**
 * FastCurl (PHP object-oriented wrapper for {@link http://curl.haxx.se/ cURL} inspired on {@link http://jamessocol.com/projects/oocurl.php OOCurl})
 *
 * TEST FILE
 *
 * Copyright (c) 2010 Antonio López Vivar
 * 
 * LICENSE:
 * 
 * This library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any
 * later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @package   FastCurl
 * @author    Antonio López Vivar <hide@address.com>
 * @copyright 2010 Antonio López Vivar
 * @license   http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

require_once('FastCurl.inc');

error_reporting(E_ALL ^ E_NOTICE | E_STRICT);

try{
	
	//Create two FastCurl objects
	$fc1=new FastCurl('http://www.yahoo.com');
	$fc2=new FastCurl('http://www.wikipedia.org');
	
	
	//Exec sequentially
	$fc1->exec();
	$fc2->exec();
	
	
	//Echo the responses
	$fc1->fetch();
	$fc2->fetch();
	
	
	//Create a FastCurlMulti container
	$fcm=new FastCurlMulti();
	$fcm->add($fc1);
	$fcm->add($fc2);
	
	
	//Exec parallelly
	$fcm->exec();
	
	
	//Echo the responses
	$fc1->fetch();
	$fc2->fetch();
	
	
	//Destroy container
	unset($fcm);
	
	
	//Basic login
	$fc1->url='http://foofoofoo.com/login.php';
	$fc1->referer=$fc1->url;
	$fc1->enable_post('name=myuser&password=mypass');
	$fc1->exec();
	
	
	//Facebook's login
	$email='hide@address.com';
	$pass='foofoofoo';

	$fc2->url='http://www.facebook.com';
	$res=$fc2->fetch('/\< *?form.*?action.*?"(?P<action>.*?login.*?)".*?charset_test.*?value.*?"(?P<charset_test>.*?)".*?locale.*?value.*?"(?P<locale>.*?)".*?charset_test.*?value.*?"(?P<charset_test2>.*?)".*?lsd.*?value.*?"(?P<lsd>.*?)"/is');
	$fc2->enable_post('charset_test='.urlencode($res['charset_test']).'&locale='.urlencode($res['locale']).'&email='.urlencode($email).'&pass='.urlencode($pass).'&charset_test='.urlencode($res['charset_test2']).'&lsd='.urlencode($res['lsd']), NULL, $res['action'], $fc2->url);
	$fc2->exec();
	
	
	//Disable POST and make another GET request
	$fc1->enable_post(FALSE);
	$fc1->url='http://www.yahoo.com';
	$fc1->exec();

	
	//Bye bye
	unset($fc1);
	unset($fc2);

}catch (Exception $e){
	echo $e->getMessage();
}

?>
Return current item: Fast Curl