I whipped up a simple ZF1 resource plugin for AngularJs called AngularZF1 and dropped it onto github. We have started using Angular at work and I thought, why not mimic how the ZendX_JQuery plugin works. Right now it doesn’t add much beyond just adding the script tag to your <head>. Enjoy, all you who are still on ZF1!
Tag Archives: php
I have been using Zend Framework 1.x at work for some time now. I appreciate the large number of components, many of which my system uses on a daily basis. Yes, it is a large library, but we have a very large application that probably does too many things.
ZF2 is coming out soon and it seems quite different from 1.x. I downloaded the betas and skeleton app, and looked at the well written tutorials, but I am still having a difficult time wrapping my mind around it. So I have decided to see if the grass is greener elsewhere. There are plenty of PHP frameworks out there to choose from, but I have one particular requirement: Oracle support. I work in a somewhat regulated space and the big vendors are preferred over the Open Source databases. And not just any Oracle support, we need to use the oci8 driver.
Most of the new frameworks prefer to use PDO for their database abstraction layer. This is fine for most people who are using MySQL or PostgreSQL. This is not great for us Oracle users. Although there is a pdo_oci extension, it is very buggy. We have to use the oci8 driver instead. And no, I cannot just switch to MySQL.
So, which of the frameworks support oci8? *feel free to correct me in your comments
|Symfony2||Doctrine||Y||According to the Doctrine 2.0x docs oci8 is supported.|
|Lithium||Internal||N||MySQL, SQLite3, CouchDB, MongoDB|
|Aura||Wrappers around PDO||N||MySQL, PostgreSQL, SQLite3, SQLServer|
|DooPHP||Wrappers around PDO||N|
|Yii||Internal||?||Found a note from 2009 saying it worked|
|Slim||-||No DB support in framework|
When I was researching frameworks 3 years ago I looked at Doctrine as a DBAL and even contributed a few patches to the project, but eventually got frustrated enough to bail on it and go with ZF’s vanilla approach. Should I try out Doctrine again or use something like Slim and keeping all my existing ZF1 database code?
About once every other week I try and spend some time at work thinking ahead. With PHP 5.4 on the horizon I began to wonder how our current Zend Framework application would fare if the SysAdmins decided to jump straight from PHP 5.2 to PHP 5.4. Would the site work at all? One way to find out. Lets install PHP 5.4RC8 and Apache 2.4.
I started by creating a fresh Ubuntu 11.10 VM. In complete disclosure, I removed some of the unneeded packages like LibreOffice first. I then cloned it so I would always have a base to work off of in the future.
Open a terminal prompt and switch to root.
sudo su -
This just makes life easier throughout the process. Normally I would recommend only switching to root when you fully need to, like when you run apt-get install or make install. Now lets make sure we have all the build environment pieces we need.
apt-get update apt-get -y -q install make g++ flex bison build-essential zlib1g-dev binutils \ cmake automake autoconf libmcrypt-dev libmhash-dev libxslt1-dev \ libtidy-dev libbz2-dev libxml2-dev libssl-dev libmysqlclient16 libmysqlclient16-dev \ libpng12-dev libpng12-0 libpng3 libjpeg62 libjpeg62-dev libxpm-dev libpcre3 \ libpcre3-dev zlib1g zlib1g-dev libltdl-dev libltdl7 pkg-config \ libcurl4-openssl-dev libfreetype6 libfreetype6-dev libc-client2007e \ libc-client2007e-dev libkrb5-3 libkrb5-dev openssl libglobus-openssl \ libglobus-openssl-dev libcurl4-openssl-dev libicu-dev libicu44 libpspell-dev \ linux-libc-dev libc-dev-bin libc-bin libc-client2007e-dev eglibc-source \ libkrb5-3 libkrb5-dev libkrb53 libkrb5support0 libncurses5-dev libncurses5 \ ncurses-base ncurses-bin ncurses-term libaio-dev libedit-dev lynx
Certainly some of those are not totally needed if we are only checking to see if things install, but I want to make sure we have lots of bases covered. Now, time to get Apache 2.4. You can skip this portion if you want to only install PHP 5.4.
For Apache we need three pieces: the Apache Portable Runtime, APR Utils, and the Httpd server itself. Feel free to find a closer mirror. This code will download the latest greatest for today and install it into /usr/local/
# APR wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz tar -xvzf apr-1.4.6.tar.gz cd apr-1.4.6/ ./configure make make install cd .. # APR Utils wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz tar -xvzf apr-util-1.4.1.tar.gz cd apr-util-1.4.1 ./configure --with-apr=/usr/local/apr make make install cd .. # Apache wget http://apache.petsads.us//httpd/httpd-2.4.1.tar.gz tar -xvzf httpd-2.4.1.tar.gz cd httpd-2.4.1 ./configure --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-deflate --enable-expires --enable-headers --enable-usertrack --enable-ssl --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-apr=/usr/local/apr/ make make install cd ..
The above worked rather painlessly for me once I knew that I had to install APR and APR Utils before the Httpd server. We will do the configuring of Apache in a bit. Lets install PHP 5.4RC8 first.
wget http://downloads.php.net/stas/php-5.4.0RC8.tar.gz tar -xvzf php-5.4.0RC8.tar.gz cd php-5.4.0RC8 './configure' '--disable-debug' '--enable-inline-optimization' '--disable-all' '--enable-libxml' '--enable-session' '--enable-xml' '--enable-hash' '--with-pear' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-layout=GNU' '--enable-filter' '--with-pcre-regex' '--with-zlib' '--enable-simplexml' '--enable-xmlwriter' '--enable-dom' '--with-openssl' '--enable-pdo' '--with-pdo-sqlite' '--with-readline' '--with-sqlite3' '--with-iconv' '--disable-phar' '--with-libedit' '--enable-exif' '--with-bz2' '--with-gettext' '--with-mcrypt' '--with-mhash' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-zlib-dir' '--with-xpm-dir' '--with-xsl' '--with-tidy' '--with-freetype-dir' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--enable-dom' '--enable-xml' '--enable-soap' '--enable-libxml' '--enable-session' '--enable-simplexml' --with-kerberos --with-curl '--with-mysql-sock' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-config-file-path=/usr/local/etc' make make install
PHP has tons of config options. I recommend checking your current install to see what it was built with and add those flags. Once nice thing here is that mysqlnd comes with PHP 5.4 so we do not have to link to an existing MySQL install. Another thing to note is that this sets php’s config directory to /usr/local/etc. Make sure to customize –with-config-file-path to wherever you want to store your php.ini.
Speaking of php.ini, lets put one in place now.
cp php.ini-development /usr/local/etc/php.ini
And lets set up where Apache can find our files (unless you like putting things in /usr/local/apache2/htdocs/).
mkdir /var/www/ chgrp -R www-data /var/www/
Ready to configure Apache? I wasn’t! It had been over 4 years since I had done a source compile (I used to use Gentoo linux). Open up /usr/local/apache2/conf/httpd.conf in your favorite editor.
- Replace instances of /usr/local/apache2/htdocs with /var/www . There should be two.
- Add index.php to the DirectoryIndex line
- I uncommented #LoadModule rewrite_module modules/mod_rewrite.so and
- #Include conf/extra/httpd-vhosts.conf because I knew I was going to need them for my later testing.
- And finally I added 2 lines to make sure we parse the PHP
AddHandler php5-script .php AddType text/html .php
I wanted to make sure Apache would start on boot so I added it to the main runlevel.
ln -s -T /usr/local/apache2/bin/apachectl /etc/rc2.d/S80apache
To find out what rcX.d you should use just execute runlevel. Shove the number it returns (2 in my case) in for X.
Moment of Truth
Three steps left. First, start up apache. If everything has gone well so far this should cause you no grief.
Create a test php page:
echo "<?php phpinfo();" | cat > /var/www/index.php
And finally navigate to http://localhost/ on your VM.
I re-ran this process a couple times on copies of the initial VM clone to refine it a bit. It all worked stellar today. YMMV of course. I had to do some additional steps after this to test our ZF application since we use Oracle instead of MySQL. So far I have only found one minor Notice that popped up in 5.4 which was trivial to clean. Now if I could convince the SAs to upgrade to 5.4 once it goes gold…
Enjoy testing your code on PHP 5.4!
Back at php|tek11 Rob Allen gave a talk on optimizing Zend Framework. During the tutorial he pointed out how you could cache your application config files so that they are not loaded and parsed at every request. This got me thinking about something that had been bugging me for a long time. What is the best format for your config file?
Back before ZF 1.0 there was a fair bit of confusion on how to do everything “right”, especially setting up a “modular” build. One of the first good examples out there was made by Dasprid, and he used an xml based application config. We are talking back in early 2007 when it was the wild west for ZF. Since then, I only see people using ini files.
Well, here it finally is, the official synthetic Zend_Config benchmark shootout.