Why use Redis?

Redis is a key-value data store. It’s a “NoSQL” key-value data store. More precisely, it is a data structure server.

Not like MongoDB (which is a disk-based document store), though MongoDB could be used for similar key/value use cases.
The closest analog is probably to think of Redis as Memcached, but with built-in persistence (snapshotting or journaling to disk) and more datatypes.

Redis is a good if you want a highly scalable data store shared by multiple processes, multiple applications, or multiple servers. As just an inter-process communication mechanism it is tough to beat. Its speed also makes it great as a caching layer.

Below are some of the most common Redis use cases –
1. Session Cache
2. Full Page Cache (FPC)
3. Queues

Pros of Redis:
• It’s blazing fast
• it supports a wide variety of data types
• it’s open source and has an active community
• it’s simple to install and has no dependencies
• stores generic data types for any purpose
• easy to get started on a single cheap/free server

Cons of Redis:
• your dataset has to fit comfortably in memory
• no joins or query language
• you have to learn lua if you want something like stored procedures

The following link is superb to learn the basics of redis
http://try.redis.io/

Most popular PHP frameworks

Nowdays PHP is most favorable coding language among web developers and bloggers because of it is open source.PHP, known as the most popular server-side scripting language in the world, has evolved a lot since the first inline code snippets appeared in static HTML files. The reason behind popularity of PHP is its flexibility, database support, interactivity and plenty of frameworks.

What PHP frameworks do:

  • Make speed development possible
  • Provide well-organized, reusable and maintainable code
  • Frameworks Follow the MVC (Model-View-Controller) pattern that ensures the separation of presentation layer and logic
  • Follow object-oriented programming tools
  • Provide Security feature like (CSRF …)

1. Laravel (released in 2011),
2. Symfony
3. CodeIgniter (released in 2006
4. Yii 2
5. Phalcon (released in 2012)
6. CakePHP (released in 2005)
7. Zend Framework
8. Slim (PHP micro framework)
9. Aura
10. FuelPHP

Top 10 websites built with PHP technology !

There are 82% websites are developed using php. Php have many framework so different websites are using different -different framework.
Below are the top 10 websites which are built with php technology.

Facebook
Wikipedia
Yahoo
Flickr
Wordpress
Tumblr
Friendster
Istockphoto
sourceforge .net
PolicyMantra

It is a mix of popularity and traffic :)

WHY PHP cURL HTTP CODE return 0 (zero)

If you try to connect with the server, then you can get a return code from it, otherwise it will fail and you get ZERO.
So if you try to connect to “www.yahoo.com/zxcv” you will get a return code of 400, if you go directly to yahoo.com, you will get 302 (and then 200 if you forward to the next page… , and if you go to “yahoocom” you will get a 0 (host no found), so with the last one, there is nobody to send a code back.

Tested using the code below.

 

PHP CURL

How to detect a mobile device with PHP?

Get user agent of user and redirect user to mobile version.

Add more button for upload multiple files

Below is the code to upload multiple files with add more button. It shows one browse option.

You need to include jquery min file to execute this code

Add js file in header
<script src=”//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>

<script type=”text/javascript”>
$(document).ready(function(){
var maxField = 10; //Input fields increment limitation
var addButton = $(‘.add_button’); //Add button selector
var no = $(‘.no’); //Add button selector
var wrapper = $(‘.field_wrapper’); //Input field wrapper
var fieldHTML = ‘<div><input type=”file” name=”field_name[]” value=””/><a href=”javascript:void(0);” class=”remove_button” title=”Remove field”>Remove</a></div>’; //New input field html
var x = 1; //Initial field counter is 1
$(addButton).click(function(){ //Once add button is clicked
if(x < maxField){ //Check maximum number of input fields
x++; //Increment field counter
$(wrapper).append(fieldHTML); // Add field html
}
});
$(wrapper).on(‘click’, ‘.remove_button’, function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent(‘div’).remove(); //Remove field html
x–; //Decrement field counter
});
});

</script>

HTML:
<form method=”post” enctype=”multipart/form-data”>
<input type=”text” class=”no” value=””>
<div class=”field_wrapper”>
<div>
<input type=”file” name=”field_name[]” value=””/>
<a href=”javascript:void(0);” class=”add_button” title=”Add field”>Add</a>
<input type=”submit” name=”save” value=”SAVE”/>
</div>
</div>
</form>

PHP:

Once the multiple form fields are submitted, then you can get the values as an array in PHP script.

<?php
print ‘<pre>’;
print_r($_FILES[‘field_name’]);
print ‘</pre>’;

?>

How to Set Timezone in Laravel 5.1

Set Timezone in Laravel 5.1
We can set timezone in config file config/app.php at below section.
You have to set a timezone supported by PHP. An overview about available timezones can be find here: http://php.net/manual/en/timezones.php

/*
|————————————————————————–
| Application Timezone
|————————————————————————–
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
//  Default value of timezone is ‘UTC’,
‘timezone’ => ‘UTC’,

// I have changed it to ‘Asia/Kolkata’ because i need indian timezone.

‘timezone’  => ‘Asia/Kolkata’,

How to get server key for FCM notification

Login https://console.firebase.google.com
Click the settings icon next to your project name at the top left of the new Firebase Console
Click Project settings
Click on the Cloud Messaging tab
The key is right under Server Key
If your key is not correct it will return Error 401.

Please refer attached Image

 

 

How to reset all fields of a form through JavaScript or jQuery?

In java script form.reset() is a DOM element method (not one on the jQuery object), so you need:
If you want to you use jQuery follow below code

Or In java script :