Skip to content

Commit

Permalink
Fixed syntax, realized I was coding PHP, not Java and removed all var…
Browse files Browse the repository at this point in the history
…iable casting :(
  • Loading branch information
unknown committed Oct 19, 2012
1 parent 88bc5c4 commit 9e5c1f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CFBalancerPHP</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
26 changes: 13 additions & 13 deletions CFBalancePHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ class CFBalancerPHP {
* Change these as necessary, however we do not recommend running the CFBalance daemon on a remote PC,
* as it will report invalid statistics for the local node's CPU / bandwidth utilization.
*/
private const WEBSERVICE_HOST = "localhost";
private const WEBSERVICE_PORT = 44444;
const WEBSERVICE_HOST = "localhost";
const WEBSERVICE_PORT = 44444;

// Stores the rolling debug log for timing purposes
private string $debugLog;
private $debugLog;

// Emergency variable. True if this function is defunct and should not be used.
private int $dead;
private $dead;

// For performance-tracking
private int $timer;
private $timer;

/** This initializes the CFBalancerPHP class.
* We also initialize the $timer variable here as well so we can debug print every step of the way,
Expand All @@ -29,11 +29,11 @@ public function __construct() {
*/
public function getNodeList() {
if ($dead) {
$this->debug(__FUNCTION__)
$this->debug(__FUNCTION__);
return null;
}
resource $handle = $this->openWebService();
string $nodeListRaw = null;
$handle = $this->openWebService();
$nodeListRaw = null;

// FIXME: add timing code here as well to ensure that the socket never hangs for more than 15ms
// if it does hang, debug print, and mark us as dead, and return null.
Expand All @@ -45,7 +45,7 @@ public function getNodeList() {
while (!stream_get_meta_data($fp)['timed_out']) {
fwrite($handle, "L");
while (!feof($handle)) {
$nodeListRaw .= fread($handle, 128)
$nodeListRaw .= fread($handle, 128);
}
$this->debug("Got NodeList in raw form from server.");
//process raw nodelist into array
Expand Down Expand Up @@ -78,7 +78,7 @@ public function processNodeList($raw) {
*/
public function checkAndRedirect($postfix) {
if ($dead) {
$this->debug(__FUNCTION__)
$this->debug(__FUNCTION__);
return null;
}

Expand All @@ -91,7 +91,7 @@ public function checkAndRedirect($postfix) {
*/
public function getRedirectNode() {
if ($dead) {
$this->debug(__FUNCTION__)
$this->debug(__FUNCTION__);
return null;
}

Expand Down Expand Up @@ -120,9 +120,9 @@ private function openWebservice() {
*/
private function debug($text) {
if ($dead) {
$debugLog .= "[ "microtime(true) - $timer"ms ] DEAD! - ".$text." was called. Ignoring. /r/n";
$debugLog .= "[ ".microtime(true) - $timer."ms ] DEAD! - ".$text." was called. Ignoring. /r/n";
} else if (DEBUG) {
$debugLog .= "[ "microtime(true) - $timer"ms ] ".$text."/r/n";
$debugLog .= "[ ".microtime(true) - $timer."ms ] ".$text."/r/n";
}
}

Expand Down

0 comments on commit 9e5c1f9

Please sign in to comment.