PHP Laravel Redis caching examples

1. Directly with Redis class
config/app.php

‘providers’ => array(
‘Illuminate\Redis\RedisServiceProvider’,
),
‘aliases’ => array(
‘Redis’ => ‘Illuminate\Support\Facades\Redis’,
),

config/database.php

‘redis’ => array(
‘cluster’ => false,
‘default’ => array(
‘host’ => ‘127.0.0.1’,
‘port’ => 6379,
‘database’ => 0,
),
),

PHP code will look like this
$redis = \Redis::connection();
if ($redis->exists($cacheKey)) {
$results = json_decode($redis->get($cacheKey),true);
}
else {
$results =select_array_from_mysqldb( $dblink );
$redis->set($cacheKey,json_encode($results));
}

2. Through Cache class
config/cache.php

return array(
‘driver’ => ‘redis’,

‘prefix’ => ‘kleidoo’,
);

PHP code will look like this
$minutes = 60;
if (\Cache::has($cacheKey)) {
$results = json_decode(\Cache::get($cacheKey),true);
}
else {
$results =select_array_from_mysqldb( $dblink );
\Cache::put($cacheKey,json_encode($menutags),$minutes);
}

PHP enable debug

error_reporting(-1);
ini_set(‘display_errors’, ‘On’);

PHP SoapClient enable debug

1. Add trace attribute to SoapClient when intialize it.
$soapclient = new SoapClient( $soapurl, array(‘trace’ => 1) );

2. Add the following 2 methods after making a soap call
echo $soapclient->__getLastRequest();
echo $soapclient->__getLastResponse() ;

stdClass or Array ?

The usual approach is

Use objects when returning a defined data structure with fixed branches:

$person
-> name = “John”
-> surname = “Miller”
-> address = “123 Fake St”

Use arrays when returning a list:

“John Miller”
“Peter Miller”
“Josh Swanson”
“Harry Miller”

Use an array of objects when returning a list of structured information:

$person[0]
-> name = “John”
-> surname = “Miller”
-> address = “123 Fake St”

$person[1]
-> name = “Peter”
-> surname = “Miller”
-> address = “345 High St”

Objects are not suitable to hold lists of data, because you always need a key to address them. Arrays can fulfill both functions – hold arbitrary lists, and a data structure.

Therefore, you can use associative arrays over objects for the first and third examples if you want to. I’d say that’s really just a question of style and preference.

how-to get current hostname in javascript

window.location.host or document.location.host : you’ll get sub.domain.com:8080 or sub.domain.com:80
window.location.hostname or document.location.hostname: you’ll get sub.domain.com
window.location.protocol or document.location.protocol: you’ll get http:
window.location.port or document.location.port: you’ll get 8080 or 80
window.location.origin or document.location.origin: you’ll get http://sub.domain.com *

Free DNS Servers List
208.67.220.220
67.138.54.100
207.225.209.66

display parameter

display: block
comment: for example <div> element takes the whole line as 100% width.

display: inline
comment: for example <div> element takes only own length and leave rest of the line to next elements

git copy from one remote to another remote

1. git branch -a
2. git checkout -b v2-markup origin/v2-markup
3. git push kleidooprivate v2-markup

git clone with a private key over ssh

1. ~/.ssh/config
Host privgit
User git
Hostname 127.0.0.1
Port 2233
IdentityFile ~/Projects/my-self-generated-keys/git/privgit

2. git clone privgit:phprivit.git
Cloning into ‘phprivit’…
Enter passphrase for key ‘/home/imran/Projects/my-self-generated-keys/git/privgit’:

git replace master on remote repo

login to remote server, go to git repository and type
git config receive.denyDeleteCurrent ignore

git push origin :master

git branch -m master-new master

git push origin master

git push origin :master-new

login to remote server, go to git repository and type
git config receive.denyDeleteCurrent true