Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
How to Zip and Unzip Files in PHP
Oct 24, 2018 @ 18:35:56

The TutsPlus.com site has a tutorial posted showing how to make use of the ZIP functionality in PHP to handle the compression and decompression of ZIP archives programatically.

Compressing files when transferring them over the internet has a lot of advantages. In most cases, the combined total size of all the files in the compressed format comes down by a nice margin. This means that you will save some of your bandwidth, and users will also get faster download speeds.

[...] One factor that can discourage you from compressing files or make the process very tiresome is the fact that you might be doing it manually. Luckily, PHP comes with a lot of extensions that deal specifically with file compression and extraction. You can use the functions available in these extensions to automatically compress files in PHP.

This tutorial will teach you how to zip and unzip (compress and extract) files to and from a zip archive in PHP. You will also learn how to delete or rename files in an archive without extracting them first.

The tutorial starts with the compression of files making use of the ZipArchive class to create a new instance, add files to compress and close it out to write the resulting archive. Next it shows the reverse, using the same class to create an instance and extraction path. There's also an example of using a loop for even more control of which files are included in the archive.

tagged: tutorial zip unzip introduction ziparchive archive compress

Link: https://code.tutsplus.com/tutorials/file-compression-and-extraction-in-php--cms-31977

SitePoint PHP Blog:
Getting Started with Assetic
Apr 14, 2014 @ 15:37:00

The SitePoint PHP blog has a new post from Lukas White today looking at the Assetic asset management library and how you can get started using it in your application.

There was a time when asset management meant little more than inserting a <link> tag or two and a couple of <script> tags into your HTML. Nowadays, though, that approach just won’t cut it. There’s performance, for one thing. [...] Also, as client-side applications have become more and more sophisticated, managing dependencies amongst scripts and libraries has become increasingly complex. Furthermore, technologies such as Less, Compass and Coffeescript require assets to be compiled, adding yet another step to the process of managing assets. In this article I’m going to look at a PHP package called Assetic which helps manage, compile and optimize assets such as scripts, stylesheets and images.

He briefly discusses asset management first, just to get everyone on the same page as far as what "assets" are and some considerations about their use. Next is an introduction to the Assetic library itself and the install/usage of a simple "AssetCollection" object. He also shows how to add assets to the object and how to configure compression and generation of the files (like with LESS). He also shows how to use the AssetManager and FilterManager object types along with the AssetFactory handler. Finally, he talks about some of the sample output and caching the tool can do with file-based cache handling.

tagged: assetic introduction asset tutorial javascript css less compress

Link: http://www.sitepoint.com/getting-started-assetic

LineshJose.com:
How To: Create A Simple CSS Compressor Using PHP
Jun 06, 2012 @ 13:44:26

In this recent post to his blog Linesh Jose shows you how to create a simple PHP-based compressor for your CSS (using some string replacement methods and a regex or two).

CSS or Cascading Style Sheets is a language used to describe the presentation of a document written in a markup language. If you’re developing a very complex design for your site, CSS scripts become very long, and takes too much time to load. But a compressed CSS script can help your website load faster and easily maintain its functionality. Here, I’ve created a very simple CSS compressor using PHP to compress or reduce CSS script size.

You can read through the example code and see how it all works or you can download the code and see a live demo of it in action. His script does the compression on the fly, but it's not a far stretch to get it set up as a part of a build to output to a file on deployment.

tagged: css compress tutorial strreplace pregreplace

Link:

PHPMaster.com:
Automatic CSS3 Prefixer and Compressor
Mar 20, 2012 @ 17:38:30

On PHPMaster.com today there's a new tutorial showing how to use a little PHP magic to compress your CSS automatically.

There are many ways to compress CSS files or automatically generate browser-specific CSS3 prefixes, but usually extra tools are used which is very annoying. I’d like to show you how such tasks can be done using only PHP.

Complete code for this small script is included in the article. It uses some regular expressions to parse the CSS and does some replacement and removal of things from the CSS content to slim it down and format it all as one line. There are some images illustrating the process also included.

tagged: css compress tutorial prefixer automatic

Link:

DZone.com:
Phar: PHP libraries included with a single file
Sep 23, 2011 @ 16:30:40

On DZone.com today Giorgio Sironi has a new post looking at an interesting, if seldom used, feature of recent PHP releases - packaging applications with phar archives.

Phar is a php extensions that provides the means for distributing code as a single archive, that does not have to be extracted to a folder before usage. The concept is similar to JVM Jars: each archive becomes a virtual directory where files can be accessed. However, the virtual folder is not limited to class loading, but you can open and read internal files as if it were decompresse into a directory.

He includes a brief "hello world" example of packaging up a script into a phar archive and executing it via PHP. He also shows how easy it is to create an archive from current code, making an archive containing the latest Doctrine 2 release for simple inclusion. Phars also allow compression and hashing but has issues with resource management and access external files.

tagged: phar archive file compress doctrine2 tutorial

Link:

NetTuts.com:
How to Use the Nettuts+ Phing Build Script
Aug 22, 2011 @ 16:50:40

NetTuts.com has come up with a Phing (the automated build tool written in PHP) build script that designers can drop in as a part of their deployment process to compress, concatenate and Prefixize all of their stylesheets and scripts.

We’ve created a build script for Phing that will give designers the ability to automatically compress, concatenate, and Prefixize all of their stylesheets and scripts — simply by typing five characters. I’ll show you how to use it in this quick tip video.

The post includes a screencast showing you how to get it all set up and working with the rest of your Phing install. They don't help you set up Phing - you'll need that already set up and running to use the task. You can grab teh script directly from github.

tagged: build script phing compress stylesheet designer prefixize tutorial screencast

Link:

Sander Marechal's Blog:
A YuiCompressorFilter for Phing
Aug 02, 2011 @ 14:16:37

Sander Marechal has been working with Phing in some of his recent development and has created something useful for compressing Javascript and CSS files on the deployment of your application - a YuiCompressor task.

I am going to write several useful extensions, the first of which is a YuiCompressorFilter. Phing already has support for a JavaScrip minifier in the form of the JsMinTask, but the yui-compressor is more useful. Not only does it usually compress better than JsMin, it can also compress CSS files. Also, because my YuiCompressor extension is implemented as a filter instead of a task you can do fancy things like minifying and concatenating files in a single step.

He includes both a sample of the task and it's configuration (the XML) in the post as well as a link to its source over on github.

tagged: javascript compress phing task css

Link:

SitePoint PHP Blog:
How to Roll Your Own JavaScript Compressor with PHP and the Closure Compiler
Aug 31, 2010 @ 17:51:08

On the SitePoint PHP blog today there's a quick new post showing you how to create a Javascript compressor tool with PHP that uses the Closure Compiler from Google.

In my previous post, I discussed the Closure Compiler's REST API. In this article, we'll develop a small PHP program that shows how the API can be used to compress JavaScript code whenever you need it.

He shows how to compress three "script" tags down into one that defines multiple files for the engine to grab and compress. This is passed into a PHP file that grabs the file and passes the data off to the Closure Compiler for handling (via curl). The result is then passed back and served up with a content type of "text/javascript" back to the browser.

tagged: closure compiler google javascript compress tutorial curl

Link:

Thomas Weidner's Blog:
Compression and Decompression for ZF
Sep 23, 2009 @ 15:26:40

As Thomas Weidner mentions in a new blog post, starting with the 1.10 release of the Zend Framework there'll be a new component to help with compressing and decompressing files - Zend_Filter_Compress/Decompress.

The new components Zend_Filter_Compress and Zend_Filter_Decompress provide a unified API for several compression formats. Actually the formats BZ2, GZ, LZF, RAR, TAR and ZIP are implemented: You can not only work with Strings, but also with Files and also with complete Directories.

He includes a quick example of how it will work with both data (like a string) and writing out the information to a compressed file. You can find out more about the component from Thomas' proposal on the Zend Framework wiki.

tagged: zendframework compress decompress

Link:

Zend Developer Zone:
Zend Platform Performance Tuning on IBM i
Feb 19, 2009 @ 19:49:03

The Zend Developer Zone has a new article posted looking to help you squeeze the most performance you can out of the Zend Platform application from Zend on your IBM i machine.

Zend Platform on IBM I provides many benefits including monitoring and advanced debugging. One of the more confusing issues that customers face with Zend Platform on IBM i is the impact on development machines. Most will try out Zend Platform in a development environment or on a development LPAR.

There's three things they suggest to tweak to help you get the most out of Platform - code acceleration, dynamic content caching and code compression.

tagged: zend platform performance tuning ibmi ibm acceleration content cache compress

Link:


Trending Topics: