Pages

Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Sunday, August 18, 2013

PHP-Convert a timestamp into facebook post time representation i.e years ago,months ago,weeks ago,days ago,hours ago,minutes ago,seconds ago format

This code is helpful for converting a timestamp field to a time stated as

years ago if it is more than an year ago
months ago if it is more than a month ago
week ago
days ago
hours ago
seconds ago

For example a post made yesterday will be shown as " 1 day ago"

Here goes the code
 <?php  
 $today = time();    
                 $createdday= strtotime($post['created']); //mysql timestamp of when post was created  
                 $datediff = abs($today - $createdday);  
                 $difftext="";  
                 $years = floor($datediff / (365*60*60*24));  
                 $months = floor(($datediff - $years * 365*60*60*24) / (30*60*60*24));  
                 $days = floor(($datediff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));  
                 $hours= floor($datediff/3600);  
                 $minutes= floor($datediff/60);  
                 $seconds= floor($datediff);  
                 //year checker  
                 if($difftext=="")  
                 {  
                   if($years>1)  
                    $difftext=$years." years ago";  
                   elseif($years==1)  
                    $difftext=$years." year ago";  
                 }  
                 //month checker  
                 if($difftext=="")  
                 {  
                    if($months>1)  
                    $difftext=$months." months ago";  
                    elseif($months==1)  
                    $difftext=$months." month ago";  
                 }  
                 //month checker  
                 if($difftext=="")  
                 {  
                    if($days>1)  
                    $difftext=$days." days ago";  
                    elseif($days==1)  
                    $difftext=$days." day ago";  
                 }  
                 //hour checker  
                 if($difftext=="")  
                 {  
                    if($hours>1)  
                    $difftext=$hours." hours ago";  
                    elseif($hours==1)  
                    $difftext=$hours." hour ago";  
                 }  
                 //minutes checker  
                 if($difftext=="")  
                 {  
                    if($minutes>1)  
                    $difftext=$minutes." minutes ago";  
                    elseif($minutes==1)  
                    $difftext=$minutes." minute ago";  
                 }  
                 //seconds checker  
                 if($difftext=="")  
                 {  
                    if($seconds>1)  
                    $difftext=$seconds." seconds ago";  
                    elseif($seconds==1)  
                    $difftext=$seconds." second ago";  
                 }  
                 echo " | ".$difftext;  
 ?>  

Wednesday, July 17, 2013

Amazon S3-RequestTimeTooSkewed The difference between the request time and the current time is too large

Recently while working on a Project which had a hosting on Amazon Cloudfront, Storage on S3 and Streaming from Amazon EC2.I came across an issue which went ok initially but became a 2 day R&D Topic for my team after a server shutdown and Reset...

While requesting bucket I got a strange error from Amazon

"RequestTimeTooSkewed The difference between the request time and the current time is too large"

I checked everything from security credentials to bucket name finally going to Amazon Support where I came to knew that i was the fault of my system clock.

Our Systems must sync to NTP-Network Time Protocol in order to sync with Amazon Cloud Services..

My server

Centos which is redhat/suse based

Here is how i resolved the same

First and foremost I installed ntp again to be on safer side and make sure every stone in path was carved to needs

Install NTP
Yum install ntp

Check from config NTP is On
Chkconfig ntpd on

If everything is going well without any warnings till now its time to finalize

Sync Server time with amazon ntp

You have to check by trying to access your bucket and adding file to it after each and every sync with following servers..its like hit and try depending on your region.

ntpdate -u 0.amazon.pool.ntp.org
ntpdate -d 0.amazon.pool.ntp.org

ntpdate -u 1.amazon.pool.ntp.org
ntpdate -d 1.amazon.pool.ntp.org

ntpdate -u 2.amazon.pool.ntp.org
ntpdate -d 2.amazon.pool.ntp.org

ntpdate -u 3.amazon.pool.ntp.org
ntpdate -d 3.amazon.pool.ntp.org

That's it that solved my issue out

Sunday, June 9, 2013

Cakephp-Convert time from ffmpeg extension to required format

Recently I used ffmeg to encode videos to flv format in one of my projects.

You need to include its php extension to perform the same or you can use the software too..I will discuss the same in some lator post..

Meanwhile after encoding videos it was returning me its time in following format

"00:04:43.77"

where as client asked me to change the same to

"00:04:43" i.e, to eliminate the millisecond part..


I used

 <?php  
 $vidlen=new DateTime($myvideolength);  
 echo "converted time=";  
 $vidlen->format("H:i:s");  
 ?>  

Saturday, December 15, 2012

Firefox Caching: Get latest page every time

Firefox Caching
Get latest page every time


Internet Explorer has a fantastic Web Cache option in Tools > Internet Options > Browsing History > Settings > called “Check for newer versions of Stored Pages:’. This option lets you override Internet Explorers smart caching option.
This is useful when you’re visiting websites that frequently have changing, dynamic data, but their meta tags or HTTP Content headers don’t tell your browser to get a new copy of the page every time. All you have to do is switch the setting to “Every time I visit the webpage“.
To access it in Firefox, simply enter this into your URL location box:
about:config
Then find the browser.cache.check_doc_frequency and change it to 1. This will force Firefox to check for a newer version of the page you’re viewing, regardless of the servers instructions, or Firefox’s default settings.
This is useful because by default Firefox is set at 3 which means that it will always used an old, cached version of the web page, unless the server specifically indicates a newer one is available. You never know if you’re getting the right stuff.
For reference, valid values for browser.cache.check_doc_frequency are:
0 – Check for a new version of a page once per session (a session starts when the first application window opens and ends when the last application window closes).
- Check for a new version every time a page is loaded.
2 – Never check for a new version – always load the page from cache.
3- Check for a new version when the page is out of date. (Default)




Sunday, July 8, 2012

CakeTime Utility class/TimeHelper in Cakephp 2.0

Use CakeTime Utility class as follows
App::import("CakeTime",'utility')
Time helper no more works in controller from cakephp 2.0 onwords.

Sunday, May 1, 2011

Fatal error: Maximum execution time of 30 seconds exceeded in

Fatal error: Maximum execution time of 30 seconds exceeded in
Faced this error while installing a PHP project on my webserver.The solution to This problem is simple Simply increase the Execution timeout in the Php.ini file till the time you are getting the error.

Search for these lines

; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 150

Bingo here you go