memcached using php and perl

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
The system uses a client–server architecture. The servers maintain a key–value associative array; the clients populate this array and query it. Keys are up to 250 bytes long and values can be at most 1 megabyte in size.
Clients use client side libraries to contact the servers which, by default, expose their service at port 11211. Each client knows all servers; the servers do not communicate with each other. If a client wishes to set or read the value corresponding to a certain key, the client’s library first computes a hash of the key to determine the server that will be used. Then it contacts that server. The server will compute a second hash of the key to determine where to store or read the corresponding value.
Perl script for fetching a Memcached result.

use Cache::Memcached;
use Digest::MD5;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $memcli = new Cache::Memcached {
    ‘servers’ => [ “″ ],
    ‘debug’ => 0
my $serviceID=$ARGV[0];
print “Service ID__”.$serviceID.” **_\n”;
my $perlKey=’perl_’.$serviceID;
my $result = $memcli->get($perlKey);
#print “already : ___”.$result.”________\n”;
if($result eq “”)
#hit a php page to set memcache values if this key does not exist.
        use LWP::UserAgent;
        #my $serviceID = 12;
        my $url= “”;
        my $ua       = LWP::UserAgent->new();
        my $response = $ua->post( $url, { ‘id’ => $serviceID } );
        my $content  = $response->decoded_content();
        $result = $memcli->get($perlKey);
else {
        print “\n cached result \n “.$result;

Now the php page

$dbOBJ = new DB();
$conn = $dbOBJ->connectDB();
if ($conn){
$qry=’select id, abc, def, ghi, jkl, mno, pqr from table where id=’.$id; $memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
$cache_result = array();
//$memcache->set($perlKey, $perlString, 0, 1);
$cache_result = $memcache->get($perlKey); // Memcached object
// Second User Request
echo “
$curser = OCIParse($conn,$qry);
OCIFetchInto($curser , $values);
$demos_result[]=$values; // Results storing in array
$memcache->set($key, $demos_result, 0, 100);
$perlString = $val1.’,’. $val2.’,’. $val3.’,’. $val4.’,’. $val5.’,’. $val6;
$memcache->set($perlKey, $perlString, 0, 10);
echo $errorMessage=’Other error';