Skip to content

Instantly share code, notes, and snippets.

@NoiseEee
Created July 29, 2015 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoiseEee/2b88e9d3774d9c48da77 to your computer and use it in GitHub Desktop.
Save NoiseEee/2b88e9d3774d9c48da77 to your computer and use it in GitHub Desktop.
<?php
class gearmanNodeNotifier {
public $dataToSend = array();
public $nodeServerPort = 2015;
public $broadcastNamespace;
public $appName;
public $nodeServer = "http://127.0.0.1/";
/**
* @return bool
* @throws Exception
*/
function notify() {
if(empty($this->dataToSend) || !is_array($this->dataToSend)) {
throw new Exception("Nothing to notify Node about! No data set");
}
$data['broadcastNamespace'] = $this->broadcastNamespace;
$data['data'] = json_encode($this->dataToSend);
$binSource = $this->nodeServer.$this->appName;
//echo "\nNODE: gonna go to: ".$binSource;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$binSource);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch,CURLOPT_PORT,$this->nodeServerPort);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
if(curl_exec($ch)===FALSE) {
throw new Exception("CURL error; did not exec()".curl_error($ch));
};
curl_close($ch);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment