Just to clarify, there's no
need to use CURL in order to pass the request through a proxy but it's likely the fasted method.
I've coded up a quick and dirty class which might help. The
file_get_contents_proxy method shows you how to use a proxy in conjunction with PHP's
file_get_contents function (key point: it uses a
context).
Also, it seems that a number of your proxies weren't allowing SSL communication so that's why I've used the same proxy in my sample class. But you can use any that you find to work.
Here's the class, sorry it's quite long and messy but *touch wood* it works for me.
PHP Code:
<?php
class DeliciousSpam
{
private $m_aUsers = array();
private $m_aSubmissions = array();
/*
Add a user to the queue of users to whom urls will be submitted.
*/
public function addUser($username, $password, $proxy)
{
$this->m_aUsers[$username] = array(
'username' => $username,
'password' => $password,
'proxy' => $proxy);
}
/*
Adds a site/url which will be submitted to del.icio.us
The optional $options array should contain an associative
array of fields which you want to send alongside the required
$url and $description fields.
*/
public function addSubmission($url, $description, $options = array())
{
$params = array_merge($options, array(
'url' => $url,
'description' => $description));
$this->m_aSubmissions[$url] = $params;
}
/*
Submit our sites/submissions, cycling through each user
*/
public function submit()
{
$aResults = array();
if (empty($this->m_aUsers) || empty($this->m_aSubmissions))
{
return $aResults;
}
foreach ($this->m_aSubmissions as $aRequest)
{
foreach ($this->m_aUsers as $aUser)
{
$szResult = $this->_call($aRequest, $aUser);
if (false !== strpos($szResult, 'code="done"'))
{
$szResult = 'SUCCESS';
}
else
{
$szResult = 'FAILED';
}
$aResults[$aRequest['url']][$aUser['username']] = $szResult;
// Del.icio.us does not like more than one request per second
// so we will sleep for a while between each request.
sleep(1);
}
}
return $aResults;
}
/*
Send an API call to del.icio.us
*/
private function _call($aRequest, $aUser)
{
// Build full URL for the API request
$szURL = sprintf(
'https://%s:%s@api.del.icio.us/v1/posts/add?%s',
$aUser['username'],
$aUser['password'],
http_build_query($aRequest)
);
// Make the request (turn error_reporting off to skip failures)
$iErrorLevel = error_reporting(0);
$szResponse = isset($aUser['proxy'])
? $this->file_get_contents_proxy($szURL, $aUser['proxy'])
: file_get_contents($szURL, false);
error_reporting($iErrorLevel);
// Return the response string, or false on error
return $szResponse;
}
/*
Function to fetch the contents of an URL
via a proxy server.
*/
private function file_get_contents_proxy($szURL, $szProxy)
{
set_time_limit(12); // Push back the timeout for the PAGE
// Define the context for file_get_contents
$aContext = array(
'http' => array(
'method' => 'GET',
'proxy' => 'tcp://'.$szProxy,
'request_fulluri' => true,
'timeout' => 10, // Timeout for fetching URL
'max_redirects' => 1
)
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents($szURL, false, $cxContext);
return $sFile;
}
}
And how to use it:
PHP Code:
// Create our mighty spam beast
$spam = new DeliciousSpam();
// Add a series of users and associated proxies
$spam->addUser('clookid10', 'sandb0x', '213.114.118.44:8080');
$spam->addUser('clookid11', 'sandb0x', '213.114.118.44:8080');
// Add a series of urls to spam/submit to del.icio.us.
// The substr(...) part is just to provide different URLs each time.
$spam->addSubmission(
'http://www.ihowd.com?TFL&'.substr(md5(time()), 0, 5),
'I Howd',
array('extended' => "The only resource you'll ever need. Howd is jam packed full of how to articles.",
'tags' => 'how to, articles',
'shared' => 'yes'));
$spam->addSubmission(
'http://www.talkphp.com/showthread.php?t=1222&rnd='.substr(md5(time()), 0, 5),
'Proxifying file_get_contents [URGENT!] - TalkPHP',
array('extended' => 'I am unsure of how to use a proxy server on top of the file_get_contents() function. If anyone were willing to help me, that would be great!',
'tags' => 'talkphp, clookid',
'shared' => 'yes'));
// Submit and show some basic output
header('Content-Type: text/plain');
var_dump($spam->submit());
?>