Dynamic Loadbalancer - PHP script for iOS load balancing
My first post here - so hi, I'm Philipp and I come from (-> username) Munich in Germany.
I setup Wowza on EC2 with the Dynamic Loadbalancing Module. This works just fine with any compatible flash player like JWPLayer. But I was not able to find a way on how to get loadbalancing to work with iOS clients.
So I went and wrote some php (my first .php script actually, so please enhance it as needed and let me know what you did):
// CONFIG START - Input in your Wowza Dynamic Loadbalancers address, your application's name and the streamname
$lburl = "http://url-or-ip-of-lb-instance:1935/loadbalancer";
$appname = "liveedge";
$streamname = "myStream";
// Config END
$content = file_get_contents ($lburl);
$replacewith = "";
$ip = str_replace('redirect=', $replacewith, $content);
header("Cache-Control: no-cache, must-revalidate");
I guess it is pretty self-explanatory, it connects to the loadbalancer URL and gets the output (least loaded server). Then it removes the string "redirect=" and puts together a 302 redirect.
So if you open the .php file from your ios device it will work just fine.
To be on the safe side I would recommend to call the file playlist.m3u8 and add an Apache Directive to the server hosting the .php:
AddType application/x-httpd-php .m3u8
Of course you should only do this if you dont plan to deliver real .m3u8 files using the same apache VHost - I recommend using a dedicated VHost for this.
JWPlayer already is capable of handling RTMP redirects from Wowza's load balancer, but this method should work reasonably well with http clients. To my knowledge, Roku doesn't handle http redirects very well, however.
You may also want to look at http_request2 library for PHP to pull XML data from the Wowza servers - the http request mechanism is about 20-30x faster than the normal PHP http mechanism.