Hi Guys,
I finally moved to a quality hosting company and am now on PHP5. I dived into learning classes, and I have written my first one. I am looking forward to hearing your thoughts on how you would have done it differently, so that I may learn more.
<?
class pinger {
protected $request;
protected $context;
protected $return;
protected $services = array(
'service1' => array('name' => "Technorati", 'url' => "http://rpc.technorati.com/rpc/ping/"),
'service2' => array('name' => "Feedburner", 'url' => "http://ping.feedburner.com/")
);
protected $method = "weblogUpdates.ping";
protected $parameters = array('Write About Property','http://www.write-about-property.com');
public function request_creator() {
return xmlrpc_encode_request($this->method,$this->parameters);
}
public function context_creator($request) {
return stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Length: 250",
'header' => "Host:" . substr($service['url'],7,0),
'header' => "User-Agent:LBaileysRPCPinger",
'header' => "Content-Type:text/xml",
'content' => $request
)));
}
public function __construct() {
$this->request = $this->request_creator();
$this->context = $this->context_creator($this->request);
}
public function ping($services) {
foreach ($services as $service) {
$this->file = file_get_contents($service[url], false, $this->context);
$this->response = xmlrpc_decode($this->file);
if (xmlrpc_is_fault($this->response)) {
$return .= "Error with: " . $service['name'] . " error was: " . print_r($this->response[faultString] . $this->response[faultCode],true) . "<p/>";
} else {
$return .= $service['name'] . " pinged. Response from server was: " . print_r($this->response,true) . "<p/>";
}
}
print_r($return);
}
}
$ping = new pinger();
$ping->ping($ping->services);