function DeleteRecord($table, $key, $super_column = null, $columns = null) { // Initialize $this->err_str = ''; $cnt_retries = 0; $flag_timeout = 0; // If we failed init, bail if ($this->flag_failed_init) { return 0; } do { try { try { // Timestamp for update $timestamp = time(); // Reset exception $tx = array(); if (!empty($columns)) { $slice_range = new cassandra_SliceRange(); //$slice_range->count = 100; $slice_range->start = $super_column; $slice_range->finish = $super_column; $predicate = new cassandra_SlicePredicate(); $predicate->column_names = $columns; } else { $predicate = null; } $cfmap = array(); $cfmap[$key][$table][] = new cassandra_mutation(array("deletion" => new cassandra_deletion(array("super_column" => $super_column, "predicate" => $predicate, "clock" => new cassandra_Clock(array('timestamp' => $timestamp)), "timestamp" => time())))); $this->client->batch_mutate($cfmap, $this->consistency); // If we're up to here, all is well $result = 1; } catch (TException $tx) { // Error occured $result = 0; $this->err_str = $tx->why; $this->Debug($tx->why . " " . $tx->getMessage()); } // If this was a timeout error if (!$result) { // If this was a timeout error if (Strcasecmp(get_class($tx), "cassandra_TimedOutException") == 0 || Strcasecmp(get_class($tx), "cassandra_UnavailableException") == 0) { // Print error and retry $this->Debug("Timeout error detected. Sleeping 1 second and retrying {$cnt_retries} / 10 times"); sleep(1); $flag_timeout = true; $cnt_retries++; // Disconnect and re-connect $this->Disconnect(); $this->ConnectToKeyspace(); } // (Otherwise - this was not a timeout) if (!empty($tx)) { // Print exception info print_r($tx); } } } catch (TException $tx) { } } while ($flag_timeout && $cnt_retries < 10); // Return result return $result; }
function InsertRecord($table, $key, $record) { // Initialize $this->err_str = ''; $cnt_retries = 0; $flag_timeout = 0; // If we failed init, bail if ($this->flag_failed_init) { return 0; } do { try { try { // Timestamp for update $timestamp = time(); // Build batch mutation $cfmap = array(); $cfmap[$key][$table] = $this->array_to_supercolumns_or_columns($record, $timestamp); // Insert $mutation_map = null; $mutation_map["{$table}"][$key] = $cfmap; $this->client->batch_mutate($cfmap, $this->consistency); // If we're up to here, all is well $result = 1; } catch (TException $tx) { // Error occured $result = 0; $this->err_str = $tx->why; $this->Debug($tx->why . " " . $tx->getMessage()); } // If this was a timeout error if (!$result) { // If this was a timeout error if (Strcasecmp(get_class($tx), "cassandra_TimedOutException") == 0) { // Print error and retry $this->Debug("Timeout error detected. Sleeping 1 second and retrying {$cnt_retries} / 10 times"); sleep(1); $flag_timeout = true; $cnt_retries++; // Disconnect and re-connect $this->Disconnect(); $this->ConnectToKeyspace(); } // (Otherwise - this was not a timeout) if (!empty($tx)) { // Print exception info print_r($tx); } } } catch (TException $tx) { } } while ($flag_timeout && $cnt_retries < 10); // Return result return $result; }
// Strip parameters if (($pos = strpos($url, "?")) > 0) { $url_parameters = substr($url, $pos + 1); $url = substr($url, 0, $pos); } $url = trim(strtolower($url)); // Strip prefix and suffix '/' if ($url[0] == '/') { $url = substr($url, 1); } if (strlen($url) > 1) { if ($url[strlen($url) - 1] == '/') { $url = substr($url, 0, strlen($url) - 1); } } // If url starts with .. it's a hack attempt if (Strcasecmp(substr($url, 0, 2), "..") == 0) { $url = str_replace("..", "", $url); } // If we have a php script with this name if (file_exists($url . ".php")) { // Set PHP_SELF and REQUEST_URI to point to the real script $_SERVER['PHP_SELF'] = $PHP_SELF = $_SERVER['REQUEST_URI'] = $REQUEST_URI = "/" . $url; if (!empty($url_parameters)) { $_SERVER['REQUEST_URI'] = $REQUEST_URI .= "?" . $url_parameters; } // Load real php script require $DOCUMENT_ROOT . "/{$url}.php"; return; } //