Posts

Showing posts with the label php

Cassandra PHPCassa & Composite Types

This post is updated inorder to support phpcassa 1.0.a.1 Cassandra Composite Type using PHPCassa phpcassa 1.0.a.1 uses namespaces in PHP which is supported in PHP 5 >= 5.3.0 Make sure you have the relavant package. The script mentioned below is the copy of PHPCassa Composite Example I will explain it step by step (1) Creating Keyspace using PHPCassa         Name => "Keyspace1"         Replication Factor => 1         Placement Strategy => Simple Strategy (2) Creating Column Family with Composite Keys using PHPCassa         Name => "Composites"         Column Comparator => CompositeType of LongType, AsciiType (Ex: 1:example)         Row Key Validation => CompositeType of AsciiType, LongType (Ex: example:1)     ...

Cassandra CQL PHP Part 2

I have explained the way to execute CQL Queries from PHP via PHPCassa in my previous blogpost here  and tutorial on cql queries here It was difficult for me to remember the syntax of update and select CQL queries for Cassandra. Hence I wrote wrappers for them which are listed below Update Counter Query: /* * $counterMap => Associative array of CounterColumn names and corresponding value for given $key * Ex: UPDATE TestCounterFamily SET 'counter'='counter'+1, 'counter2'='counter2'+3 WHERE KEY='test' */ function generateUpdateCounterQuery($columnFamily, $counterMap, $key) { $colArgs = ""; foreach($counterMap as $counter => $value) { $colArgs=$colArgs."'".$counter."'='".$counter."'+".$value.", "; } $colArgs = rtrim($colArgs,", "); return "UPDATE ".$columnFamily." SET ".$colArgs." WHERE KEY='".$key."...

Auto-Complete in Eclipse&Zend

[Try right click on project and see if there is Configure > Add PHP Support, If it is there use it] This is a inference of mine while using Eclipse/Zend as IDE for PHP in linux [Not sure abt windows] I was able to notice that PHP perspective over a SVN checked out PHP project didn't function as it was doing for a regular PHP project created via eclipse. For Ex: 1. No syntax errors where highlighted/notified 2. CTRL press over a variable or a class or a function didn't give the option to navigate to the point its declaration 3. Autocompletion was completely disabled After lots of searching, I figured out that whenever we create a project via eclipse, it will create two configuration files along with it .project .buildpath SVN projects might have these files not being configured properly or might even miss them So, inorder to overcome this, either you can create one by hand or create a new PHP project and export the files you checked out in to the newly creat...

Cassandra CQL PHP

After lots of googling I figured out how to access counter columns value via PHPCassa + CQL. Though it might not be efficient, this is all I was able to figure out after a long struggle :) First Connecting to and Selection from Cassandra Instance via PHP using PHPCassa $pool = new ConnectionPool("Stats",$servers); $raw = $pool->get(); $rows = $raw->client->execute_cql_query("SELECT 'a' FROM Impressions WHERE KEY='xxx'", cassandra_Compression::NONE); To Return Connection $pool->return_connection($this->raw); To Update Counter value via PHPCassa $pool = new ConnectionPool("Stats",$servers); $raw = $pool->get(); $rows = $raw->client->execute_cql_query("UPDATE TestCounter SET 'counter'='counter'+1 WHERE KEY='xxx'", cassandra_Compression::NONE); You can find a wrapper here So, once you are done with fetch successfully. This is the result you may get object(cassandra_CqlResult)#...

Crisps abt Design Patterns

Problems are hard solve more than that, our solution should not make our appln disobey OCP (Open to extensions and Closed to Modifications) but what if they have a quality solution pre-existing :) That's what design patterns are :P They are generic reusable solutions for commonly occuring problems in S/W Design Design patterns are of various categories if u wanna know them in detail follow the link below Design Patterns :) I was just going thro some of the most commonly used Design Patterns in PHP and I wish to give them all a small introduction Singleton: A common scenario for this is a LOG BOOK. We might be recording various events at various times. So, whenever we need to record something we ll be declaring an object for the log book class and will be WRITING using some member functions of it. But what if we want a "GLOBAL LOG BOOK" for entire appln? Then choose singleton patterns. This pattern allows instantiation of object for a class only once. For Furthe...

all* abt PHP OO :P *conditions apply :D

Hi Folks spent a day with PHP in action Book An awesome book for developers :) Wanna share some useful tips out of it 0. When ISA (Inheritance)? When HASA (Composition)? Only way to decide it is relationship if it is going to be 1:1 go for ISA 1:Many go for HASA :) Cool but true :) 1. Predict what would happen $object1 = new base(); $object2 = $object1; in PHP 4 a photocopy of present appearance of the object1 is copied to object2, any changes in object1 later ll not affect the latter :D in PHP 5 it means shallow copy :) jus the reference is returned to object2 so changes on former or latter ll reflect on latter or former too :D wanna do the PHP 5 way in PHP 4 then do $object2 = &$object1; Explicit way :) But this has the difference with the PHP5 way, in this jus the symbol table is adjusted (Clever no) :) 2. Can abstract functions be private? Don't scold me if u know the meaning of abstract class :D The answer is NOOOOOOOOO obviously :) Becaus...