Thursday, February 11, 2016

Get the dates inside the two date in PHP (YYYY-MM-DD)

<?php
function createDateRangeArray($strDateFrom,$strDateTo)
{
    // takes two dates formatted as YYYY-MM-DD and creates an
    // inclusive array of the dates between the from and to dates.

    // could test validity of dates here but I'm already doing
    // that in the main script

    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
        while ($iDateFrom<$iDateTo)
        {
            $iDateFrom+=86400; // add 24 hours
            array_push($aryRange,date('Y-m-d',$iDateFrom));
        }
    }
    return $aryRange;
}
$array = createDateRangeArray('2015-01-01','2015-01-10');
foreach($array as $dates){
    echo "'".$dates."'";
    echo "<br>";
}

?>


Sample output:
'2015-01-01'
'2015-01-02'
'2015-01-03'
'2015-01-04'
'2015-01-05'
'2015-01-06'
'2015-01-07'
'2015-01-08'
'2015-01-09'
'2015-01-10'
 

Thursday, February 4, 2016

Installing FFMPEG in CENTOS & ffmpeg-php

# vi /etc/yum.repos.d/dag.repo

click INSERT key and add this line:

[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1


save it! :wq!

# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# yum update
# yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc

# ffmpeg

 

done installing ffmpeg.

All we need to do is to install ffmpeg-php

# yum install php-gd php-devel 
1. Download the ffmpeg-php
2. Extract the archive:
# tar -xjf ffmpeg-php-X.x.x.tbz2
# cd ffmpeg-php-X.x.x/
# phpize
# ./configure
# make
# make install
# echo 'extension=ffmpeg.so' >> /etc/php.ini

now restart your httpd
# service httpd restart
 
now check your phpinfo and search ffmpeg.


 

Done, You can now use ffmpeg in your php application.

:) enjoy !



Installing DJANGO in CentOS release 6.7 (Final)

You need internet connection in your server.

# cd /opt/
# wget http://mirrors.nl.eu.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm

# rm epel-release-6-8.noarch.rpm -f

Now install python but most of CENTOS has installed python by default
# yum install python
# yum install Django

Now this is how to check the version after you successfully installed it.

# python
>>> import django
>>> print djnago.get_version()

You may now create a project
# django-admin startproject mysite
# cd mysite/

# python manage.py runserver

by default this will run in port 8000
If you want to run in other port and by IP you may type this.

# python manage.py runserver 192.168.1.85:8001

 

Done! :)

How to kill all processes via grep in once (CENTOS)

Run this command.

sample process is the httpd

# ps aux | grep 'httpd' | grep -v grep | awk '{print $2}'

This will output all process ID only.

Then run this to kill all processes.


# kill -9 `ps aux | grep 'httpd' | grep -v grep | awk '{print $2}'`

Done.