Virginia Beach Web Development Developer | Databases | Video Games | Computer Tech Support | SEO | Doodersrage

Virginia Beach Web Development Developer | Databases | Video Games | Computer Tech Support | SEO

Add Zend Framework full page cache to your bootstrap

Posted on | January 24, 2012 | No Comments

ZendFramework logo 300x79 Add Zend Framework full page cache to your bootstrap

Insert the function below into your bootstrap file.

// full page cache
protected function _initCache()
    {

	$dir = "location you would like to store cached pages";

        $frontendOptions = array(
            'lifetime' => 3600,
            'content_type_memorization' => true,
			'default_options'           => array(
			'cache' => true,
			'cache_with_get_variables' => true,
			'cache_with_post_variables' => true,
			'cache_with_session_variables' => true,
			'cache_with_cookie_variables' => true,
            ),
        'regexps' => array(
                // cache the whole IndexController
                '^/.*' => array('cache' => true),
                '^/index/' => array('cache' => true),
		// place more controller links here to cache them
                 )
        );

        $backendOptions = array(
                'cache_dir' =>$dir
        );

        // getting a Zend_Cache_Frontend_Page object
        $cache = Zend_Cache::factory('Page',
                             'File',
                             $frontendOptions,
                             $backendOptions);

        $cache->start();
    }

Assign the directory that you would like to store the cache files to the -$dir- variable. Make sure the assigned directory can be read and written to. Also add some more controller regular expressions for the extra controllers you would like to also cache to the -regexps- array.

Once setup your pages will automatically be cached to a static cache file at your assigned location on your server for an hour. If you would like to cache the files for longer than an hour, increase the -lifetime- associative array value by increasing the seconds count.

Stripping audio from a video using FFMPEG for MP3, OGG, or other formats

Posted on | January 24, 2012 | No Comments

ffmpeg logo 300x75 Stripping audio from a video using FFMPEG for MP3, OGG, or other formats

Everyone has wanted to grab the audio portion of a video at one point or another. Whether to get the audio from a music video, concert, or even a lecture. The ability to separate audio data from video data can be darned handy.

Before you can begin you will have to install FFMPEG. This guide covers some other uses and links to an install guide for use on the CENTOS Red Hat based operating system.

Also! Do not forget to keep a link to the FFMPEG documentation handy!

/usr/bin/ffmpeg -y -i "/var/www/html/myvideo.flv" -vn -sn -acodec mp3 -ac 2 -ar 44100 -ab 128k  "/var/www/html/output.mp3"

FFMPEG options read:
-y force overwriting of existing file if found
-i input file of “/var/www/html/myvideo.flv”
-vn video disabled
-sn sub-titles disabled
-acodec selected audio codec of mp3
-sc two audio channels
-ar audio rate of 44100 Hz
-ab audio bit rate of 128k
Output file of “/var/www/html/output.mp3″

If you are running Ubuntu you might run into a problem using the above as it does not come with an MP3 encoder. This page has an easy an quick way to solve this problem for you.

 

Redirecting documents with PHP, Apache, and MOD_REWRITE

Posted on | January 21, 2012 | No Comments

In document PHP redirect with HTTP code assignment:

header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://www.domain.com/new-location/" );

The two lines above will redirect the document request to the /new-location/ page if nothing has been printed to the screen. If this method if attempted after printing something to the screen or flushing the output buffer you will instead receive an error. This method is great to use if you do not have access to the HTACCESS document.

By default the –header(“Location:”)- redirect method applies a 302 status code.

This same method can be used to redirect and apply a 404 status code.

header("HTTP/1.1 404 Not Found");
header( "Location: http://www.domain.com/error/" );

Alternately you can set the 404 status code but remain in the same document.

header("HTTP/1.1 404 Not Found");

If the above line was placed within a 404.php document it would then assign the correct status code of 404 to the document header.

Changing -404 Not Found- to whatever status code you would like to use will then assign that status code.

Rewrites using the HTACCESS file:

Within any Apache environment or just about any there is a hidden file names -.htaccess- (the dot signifies that the file is hidden) this file allows for many actions to be applied to your web application but we are just going to focus on page request redirection.

Redirecting without mod_rewrite:

Redirect 301 /oldpage.html http://www.domain.com/newpage.html

The above line applies the 301 header when –oldpage.html- is requested then redirects the request to the –newpage.html- document. You can replace the 301 with a 302 for a temporarily moved page.

Assigning a 404 or any other kind of error page:

ErrorDocument 404 /404.php

This line tells apache that the requested document is an error document that should have the status code of 404 applied to it. A relative link is used to load the document within the current URI request. You can assign a direct path to the document but that would also invoke a 302 redirect after the 404. This method should not be used due to the double header assignment.  For other error status codes just replace the -404- after the –ErrorDocument- call.

Redirecting documents with MOD_REWRITE:

Using MOD_REWRITE can get confusing quickly! Luckily a good cheat sheet exists! http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/

When using MOD_REWRITE you will have to make sure that your rewrite listing follows after the two lines below.

Options +FollowSymLinks
RewriteEngine on

The first line sets the option to allow the following of symbolic links while the second line turns the document rewriting system on.

RewriteRule ^oldpage.php  http://www.domain.com/newpage.php [R=301,L]

The line above looks for any document request starting with –oldpage.php- then assigns the 301 status code and redirects the user to the direct linked –newpage.php- document. The –R=301- assigns the page status code while the –L- tells the MOD_REDIRECT to stop processing the assigned redirects. The –L- assignment is best practices as it prevents any future redirects and makes sure the users page load remains speedy. Redirects set within the HTACCESS file are read line by line of each page load. Your best bet is to keep this list as short as possible.

Redirecting all requests to another domain:

RewriteRule ^/(.*)  http://www.domain.com/$1 [R=301,L]

This redirect looks very much like the previous one but uses a wild-card variable assignment. This is then thrown to the -$1- variable.

Redirecting non-www to the www sub-domain:

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

The above sets the rewrite condition of the domain without an assigned www sub-domain then redirects the user and the requested URI to the www sub-domain.

Well that’s the basics!

Generating a thumbnail image with FFMPEG

Posted on | January 20, 2012 | 1 Comment

ffmpeg logo 300x75 Generating a thumbnail image with FFMPEG If you would like to know how to compress a video for the iPhone or how to quickly use FFMPEG-PHP use this guide: CONVERT VIDEO TO IPHONE FRIENDLY H264 WITH FFMPEG

/usr/bin/ffmpeg -y -itsoffset -6 -i "/var/www/html/myvideo.mpg" -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 "/var/www/html/mypic.jpg";

The above will generate a JPEG (Joint Photographic Experts Group) with a MIME type of image/jpeg thumbnail for myvideo.mpg then store it at the assigned location (/var/www/html/mypic.jpg). Once your thumbnail has been generated you can use it in anything that supports the image type; web development, desktop application, etc.

FFMPEG options:
-y overwrite file if exists
-itsoffset the time offset in seconds (6 for this example. Great feature if you have many videos that start fading from black.)
-i input file (/var/www/html/myvideo.mpg) Double quotes are not needed but suggested if you are linking to a file-name with spaces in it.
-vcodec video codec settings (currently mjpeg for the Motion JPEG codec)
-vframes number of frames to capture (currently 1)
-an tells ffmpeg not to capture audio
-f force input (currently rawvideo)
-s frame size (currently 320×240)
Then finally the output file location. (/var/www/html/mypic.jpg)

All available frame sizes can be viewed within the FFMPEG documentation.

keep looking »
  • Social

  • Facebook

  • Facebook

  • Portfolio

    Optimized page source for search engines by removing in page CSS and JavaScript and moving content as close to the top of the page as possible.
    Provided support and code updates for an oscommerce install.
  • Twitter

  • My Tumblr

    • photo from Tumblr

      Pork chops, broccoli, mashed potatoes, and hollandaise.


    • photo from Tumblr

      Steak and brussel sprouts.


  • Alexa Rank