Posts tagged 5
After finding different hosting companies having wildly different policies when it comes to what's enabled and what isn't in PHP, I've built a generic file download class which should work in almost all situations.
This is the first version so there are some improvements to be made and if you download it, you'll see where some improvements may be made. I will be releasing another version when I've had time to do some further work on it. For now you can find the source code plus any community improvements here: http://www.refactormycode.com/codes/440-universal-file-download-class
I should also mention that this class has been cleaned of some application specific code, so if there's any disjointed bits I apologise - I have tried to deal with any discontinuities before posting but there may be something i've missed (this is also the reason for the bunch of if's in get_file() if you are to use this as is you may want to replace them with your own custom code).
I work on all sorts of little personal projects in my spare time, most of which don't ever make it to a release (mainly due to time issues), and recently I've been finding more and more instances where I could do with some kind of object relational mapper (ORM) library to assist me.
In a very small nutshell, an ORM system will allow you to take the relevant parts of a database schema and functionality and map it to classes that you have written to effectively lower the barrier between the database and whatever it is you're writing.
This makes the interface to the database more fluid, and allows for automated building of SQL and other higher order operations to be performed easily, without having to worry too much about the actual mechanics of what is going on between your application and the database.
At work we use our own in house ORM system to achieve what we need to do in this regard, but I can't reasonably expect to use this for everything I do from now on as it is the property of the company I work for. Not only that, but just staying with what you know doesn't really help you improve on what you have, or gain new perspectives on what you're working with.
So, I thought I'd go off to Google, do a bit of searching, and find some ORM examples that I can use to knock together my own ORM library to do the things I need, but then I came across PHP Doctrine...
PHP Doctrine is fairly new and is described by its developers as follows:
"Doctrine is an ORM (object relational mapper) for PHP 5.2.x+ that sits on top of a powerful DBAL (database abstraction layer). One of its key features is the ability to optionally write database queries in an OO (object oriented) SQL-dialect called DQL inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains a maximum of flexibility without requiring needless code duplication."
This sounded interesting so I decided to have a quick(ish) look through the user manual and got hooked! You can do a tonne of stuff with it, and in some ways its like having a (good) version of a tool like PHPMyAdmin that you can use on a system level - pretty much anything you could want to do in a database they have a map for which is great.
I'm not saying I'd use all the functionality they provide particularly, but a large chunk of it solves all my problems, saves me having to write my own, and being based on PHP 5.2+ I know it's modern, up-to-date and really taking full advantage of what the newer PHP versions have to offer.
If you use or are thinking of using a PHP based ORM solution in your projects, I'd seriously suggest having a look at the manual for PHPDoctrine before you write your own. Like anything, I have to admit that it does also have a couple of niggly bits of functionality that IÂ don't like, but really and truly, the pro's of it seriously out-weigh the cons.
You can read more about PHP Doctrine on its website here: PHPDoctrine
So, you want or need to stream multimediaÂ content from your website; you don't have time or money to figure out or pay someone to figure out how to do what you need; and you need it toÂ look reasonably pro.
Where do you go?
Â It's a fantastic, versatile free piece of software you can just plug into any website and use to start streaming content right away!
The best thing however, is that it works really well alongside the Red 5 streaming flash server via the oflaDemo app, and as such completes the package of a free streaming flash solution that looks good and performs well.
Just remember, when following the examples of how to get it to work with at least true streamsÂ (i.e. not progressive downloads)Â give the mediaplayer.swf an absolute url
If anybody needs help getting this to work with Red 5 feel free to drop me an email or leave a comment and I'll help you out
After having no end of issues with the proprietary flash media server 2 from Adobe I decided to give installing the Red5 open source version a go instead.
I have to say I was fairly impressed with just how easy it was to get running without having to do any of the faffing around that was required to get FMS2 running.
Here is the process in a nutshell:
- Download and install the Java Development Kit (jdk) from here (I used the rpm version of JDK 6 Update 2): http://java.sun.com/javase/downloads/index.jsp
- Download and extract Apache ant from here: http://archive.apache.org/dist/ant/binaries/apache-ant-1.6.5-bin.tar.gz
- Copy the extracted apache-ant-1.6.5 folder to /usr/local/ant
- Setup the environment variables to include the path for java and ant by typing the following at the shell prompt:PATH=$PATH:$HOME/bin:/usr/local/ant/bin
export PATHThen also remember to add this toÂ /etc/profile so the settings don't get lost the next time you login
- Download and extract the Red5 server from here: http://osflash.org/red5
- cd to theÂ Red5 directory you just extracted and type the following at the shell prompt toÂ allow java to retrieve the files it needs from the net and compile and run the server as a background process (the module retrieval is automatic and only has to be done once):ant server &Â
- Then that's it it's running. In my case I needed to kill the ant/java processes running the server after the java modules were initially retrieved and the server built for the first time, but the second time it was fineÂ even though it did take about 30 seconds to fully startup - this may just be a glitch onÂ my system as IÂ have a lotÂ of other stuff also going on.
- The final step is to test it. This can be done by moving the contents of the webapps/root/demos/ folderÂ from theÂ extracted Red5 directory to a webserver somewhere (I don't think it hast to be the same machine) and then viewing the list of demos in the index.html file.I started off by using the port tester to make sureÂ the demo apps could actually connect to the server on the ports they were meant to (basically rtmp port 1935) and then moved onto testing the video streaming app and then tried a proper live broadcast through the server using theÂ simpleBroadcaster app to two friends who were logged on using the simple subscriber app. All worked well especially as far as the video was concerned though the audio was a little crackly on my live broadcast - this could just be the quality of home connections however.The onlyÂ last not is just a simple reminder that when running theÂ test apps you'll need to specify the server they need to connect to - theÂ apps are setup to accessÂ rtmp://localhost/[APP_NAME] but if you're not running these apps as a local user you will need to change localhost to the name or ip of the serverÂ Red5 is installed on
So far I'm quite happy with Red5 as a free (very important) alternative to FMS2, but should you be looking for a commercial product as this is not quite up your streetÂ (that is a cheaper than FMS2)Â then take a look at this instead: http://www.wowzamedia.com/index.html
Wowza only requires java to run and is like a very polishedÂ commercial version of the Red5 server (it wasÂ actually through installing Wowza that I worked out what to do with the web apps for Red5 - having had no previous experience in flash streaming other than literally installing FMS2)Â which has a very reasonable price tag in comparison to the cost of FMS2
Just before I go I just need to mention the map below - Red5 ask you to add yourself to their user map if you're using the software so I have - you can find me in Brighton, England