-
-
Save NoiseEee/2b88e9d3774d9c48da77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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