PHP Parse HLS M3U8 TS Links








function parseHLS($file, $tag=".ts") {
$return = array();
$i = 0;
$handle = fopen($file, "r");
if($handle) {
while(($line = fgets($handle)) !== FALSE) {
if(strpos($line,"EXT-X-STREAM-INF") !== FALSE) {
if ($c=preg_match_all ("/.*?(BANDWIDTH)(.*?)(,)(RESOLUTION)(.*?)(,)/is", $line, $matches)) {
$return['data'][$i]['bandwidth'] = str_replace("=","",$matches[2][0]);
$return['data'][$i]['resolution'] = str_replace("=","",$matches[5][0]);

if($tag==".ts") {
if(strpos($line,".ts") !== FALSE) {
$return['data'][$i]['url'] = str_replace(array("\r","\n"),"",$line);

if($tag==".key") {
if(strpos($line,".key") !== FALSE) {  

preg_match( '/URI="([^"]*)"/i', $line, $array );
//print_r( $array[1] ) ;

//$return['data'][$i]['url'] = str_replace(array("\r","\n"),"",$line);
$return['data'][$i]['url'] = str_replace(array("\r","\n"),"",$array[1]);


if($tag==".m3u8") {
if(strpos($line,".m3u8") !== FALSE) {
$return['data'][$i]['url'] = str_replace(array("\r","\n"),"",$line);

return $return;

echo "<pre>";

// Get other m3u8 files from m3u8 master manifest 
$u = parseHLS("encoded-03-31-16-thu-jun-2017.m3u8", ".m3u8");


// Get TS segment files from m3u8 manifest 
$u = parseHLS("encoded-03-31-16-thu-jun-2017.360.m3u8", ".ts");


// Get key file from m3u8 manifest 
$u = parseHLS("encoded-03-31-16-thu-jun-2017.360.m3u8", ".key");


echo "</pre>";



[data] => Array
[0] => Array
[bandwidth] => 654000
[resolution] => 568x320
[url] => 1080p/encoded-03-31-16-thu-jun-2017.m3u8

[1] => Array
[bandwidth] => 2849000
[resolution] => 568x320
[url] => 720p/encoded-03-31-16-thu-jun-2017.m3u8

[2] => Array
[bandwidth] => 1033000
[resolution] => 568x320
[url] => 360p/encoded-03-31-16-thu-jun-2017.m3u8



[data] => Array
[0] => Array
[url] => encoded-03-31-16-thu-jun-201700000.ts

[1] => Array
[url] => encoded-03-31-16-thu-jun-201700001.ts

[2] => Array
[url] => encoded-03-31-16-thu-jun-201700002.ts

[3] => Array
[url] => encoded-03-31-16-thu-jun-201700003.ts

[data] => Array
[0] => Array
[url] => encoded-03-31-16-thu-jun-2017.key



PHP in Amazon Lambda

Clone or Download this GitHub Repo

Make new folder lambda in current working directory of EC2 server
# mkdir lambda

Upload 2 files from zip to Amazon EC2 server Instance in folder lambda

– index.js
– php (binary)


'use strict';
exports.handler = function(event, context, callback) {
var exec = require('child_process').exec;

  exec('./php -v', function (error, stdout, stderr) {
      console.log('stdout: ' + stdout);
      console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('Exec error: ' + error);

Go inside folder lambda

# cd lambda
# zip -r ../ *

Copy for AWS S3 bucket

# aws s3 cp ../ s3://bucket-name/

How to install AWS CLI?

Create new Lambda Function from AWS Console with NodeJS Runtime*

Name*: phpv
Runtime*: Node.js 4.3
Code entry type: Upload a file from Amazon S3
S3 link URL*:

Handler*: index.handler
Role*: Lambda Basic Execution

All other info will be default**

Save & Test

“PHP 5.6.5 (cli) (built: Jul 21 2015 18:56:08) \nCopyright (c) 1997-2014 The PHP Group\nZend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies\n”

Free SSL Certbot

Certbot, It was Let’s Encrypt Client previously. Automatically enable HTTPS on your website with EFF’s Certbot, deploying Let’s Encrypt certificates.

Server Support

– Apache
– Nginx
– Haproxy
– Plesk

OS Support

– Web Hosting Service
– Debian 7 (wheezy)
– Debian 8 (jessie)
– Debian 9 (stretch)
– Debian testing/unstable
– Debian (other)
– Ubuntu 17.04 (zesty)
– Ubuntu 16.10 (yakkety)
– Ubuntu 16.04 (xenial)
– Ubuntu 14.04 (trusty)
– Ubuntu (other)
– Gentoo
– Arch Linux
– Fedora 24+
– CentOS 6
– RHEL 6
– CentOS/RHEL 7
– FreeBSD
– OpenBSD 5.9
– OpenBSD 6.0+
– OpenBSD (other)
– macOS
– Devuan Jessie 1.0
– Devuan (other)
– Other UNIX
– Non-UNIX

Install on Ubuntu 17.04 (zesty) Apache

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache

Get Started

$ sudo certbot --apache

$ sudo certbot --apache certonly

Automating renewal

$ sudo certbot renew --dry-run

$ sudo crontab -e

30 1 * * * /usr/bin/certbot renew --quiet

It will run renewal command at 1:30 am, every day.

PHP Warning: PHP Startup: Unable to load dynamic library /usr/lib64/php/ modules/

CentOS 7 with PHP

# php --ini
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/’ – /usr/lib64/php/modules/ undefined symbol: php_pcre_exec in Unknown on line 0
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/10-opcache.ini,

Install Apache, MySQL, PHP 5.6 on Centos 7


# yum install php-zip

# service httpd restart
Redirecting to /bin/systemctl restart httpd.service

PHP Check Loaded Modules

# php -m
[PHP Modules]
Zend OPcache

[Zend Modules]
Zend OPcache

PHP Check Loaded ini files
# php --ini

# php -v
PHP 5.6.31 (cli) (built: Jul 6 2017 08:06:11)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Install Apache, MySQL, PHP 5.6 on Centos 7

Install Apache

# yum update
# yum install httpd
# systemctl start httpd.service

Now Browser your Apache Server http://Server_IP_address/

Enable Apache to start at server boot

# systemctl enable httpd.service

Install Mariadb MySQL

# yum install mariadb-server mariadb
# systemctl start mariadb
# mysql_secure_installation

Enable MySQL to start at server boot

# systemctl enable mariadb.service

Install PHP 5.6

Install EPEL repository

# rpm -Uvh

Note: Make sure you installed “epel-release-7-5.noarch.rpm” else google it for different location …. search on Google “index of” + epel-release-7-5.noarch.rpm

Install remi repository

# rpm -Uvh

Note: Make sure you installed “remi-release-7.rpm” else google it for different location

Enable remi

# yum --enablerepo=remi,remi-php56 install php php-common

Install php 5.6 on Centos 7

# yum --enablerepo=remi,remi-php56 install php-cli php-pear php-pdo php-mysql php-mysqlnd php-pgsql php-sqlite php-gd php-mbstring php-mcrypt php-xml php-simplexml php-curl php-zip

# systemctl restart httpd.service
# chown -R apache:apache /var/www/html/

# chmod -R 775 /var/www/

<?php phpinfo(); ?>


Top 10 Tutorials for your Drupal Website

Drupal is one of the most popular and powerful content management systems. Creating your website with Drupal will allow you endless options for design and function. Use these 10 Drupal tutorials to easily give your website features and options you may have never thought possible.

1. Tutorial For Site Setup

Every Drupal website owner should begin with a basic site-building tutorial. The first thing to do, after getting Drupal-compatible web hosting, is to review such a tutorial to create your site’s key elements. This site-setup tutorial will walk you through building your website’s administration menu, site editor, pages, menus, and slideshows.

2. Update Drupal Using Minor Updates and Patches

There are a few types of updates you will come across as a Drupal website owner including, minor, major and patch updates. This tutorial will show you how to keep your installation current to avoid bugs and errors, and maintain the latest module compatibility. Patch updates are often aimed at fixing bugs or security issues and may be released at any time. Minor updates fix site functions errors, and are released less often.

3. Autoloading Awesomeness

This tutorial will show you how to take advantage of autoloading in your visitors web browsers. This is helpful when you want to display video or other media without the user having to click ‘Play.’ Use the Auto-loading Awesomeness tutorial to follow in the steps of major media and social companies who know rely on the feature, such as Facebook and Instagram.

4. Preparing Your Site for Drupal 8

The latest release of Drupal, as of 2017, is Drupal 8. This tutorial will help you get prepared for a major update to any outdated Drupal sites. IT discusses manual site audits, security updates and audit modules. While your updated your Drupal and installing Drupal 8, you should check that you have Drupal optimized web hosting, so that you can make the most of your Drupal installation.

5. Installing and Editing Drupal Themes

This tutorial is perhaps among the most important for any Drupal user. It shows you how to install and modify themes for your Drupal site by giving you the basics on how themes work. After reviewing this tutorial, even a beginner will be able to choose and install a Drupal theme that’s right for their site. Those with just a few minutes on their hands can learn how to change colors, module positions and add or remove elements.

6. Drupal SEO Tutorial

If you’re focused on marketing and Search Engine Optimization, then this is the Drupal tutorial for you. It will teach you how to create SEO-friendly posts, tags, and headers. Beginning with a focus on mobile Drupal templates and themes, this handy guide will ensure your site doesn’t get buried in the search results.

7. Drupal Modules Tutorial

This tutorial is invaluable for those who want to begin developing Drupal modules and backend coding. It will show you how to use Object-Oriented PHP to create Drupal modules with function in the backend of your site and interactive features for your website’s frontend. Some PHP knowledge is required for this tutorial. Object-Oriented PHP will keep your Drupal site coding from being redundant, and save you time behind the keyboard.

8. Use Node.js with Drupal

Many web developers are used to node.js and want full javascript integration on their Drupal based website. This tutorial will teach you to seamlessly integrate the popular node.js package with Drupal to use them inherently together. Using Node.js on your Drupal site will allow you to build web applications that are as scalable as you need them to be. This would work great for any new social media site or mobile application.

9. Create a Custom Slideshow

Slideshows have many purposes on websites, including rotating content to keep the site fresh, and ensuring certain content has a front-page standing. This tutorial will show you how to easily create a slideshow on your Drupal site using theme libraries and the Slick module. It involves some simple HTML markup and Java which you can copy and paste or make modifications to. Your finished product will look great on any business website, and will rotate three or more images or embedded media modules at your desired speed.

10. Loop Over Objects

This tutorial is among the more advanced on the list, but should appeal to anyone with even a little coding background. It will show you how to loop over objects using the built-in tag IteratorAggregate. If you’re looking to get started practicing your PHP skills on a live site, this tutorial is a great choice and will provide convenient, functional results.

Drupal can be used for personal websites, business and corporate sites, and even blogs. It’s a diverse CMS that allows countless customizations. By following these tutorials you will gain a better understanding of your Drupal interfaces, and be able to add creative elements to your website.

A Guide to Growing Your Agency by Upselling Clients

How upselling clients can help your agency to grow
As a web design agency are you currently concentrating most of your energies on attracting new clients as opposed to upselling existing ones? If you are then this could be a mistake. It can often take a lot less effort to sell a further service to a client you have already worked with than it does to persuade a new client to hire you. Most importantly, the financial rewards can be impressive and can help with the growth of your agency.

It’s unlikely that clients are going to completely update their website on a regular basis so you need to think carefully about services which you can offer. Do not forget that clients are going to be most interested in services that can secure them increased leads, sales and revenue. Let’s take a look at some of the ways in which you can upsell existing clients.

Optimising conversions
Conversions are likely to be one of the most important considerations for your clients. You can offer them the ability to optimise conversions by using the very latest functionality in areas such as check out functionality and live chat features.

Optimising performance
Website performance is always an important factor when it comes to attracting and retaining customers. This is why offering to monitor the performance of a client’s website, and provide suggestions for optimisation, is a good idea. Have any features been added that make the website slow to load, for instance. This is an important issue as slow load times are one of the major factors when it comes to deterring people from using a website.

Optimising analytics
If analytics are not optimised then it’s hard to tell how well aspects of a website are performing. It’s important that a client has the latest analytics in place in order for them to see where changes might be necessary in order to maximise ROI from their website. If you can offer them your analytics expertise you are upselling a vital product.

How to charge when upselling clients
There may not be a one size fits all option when it comes to upselling; you have to decide on solutions that are the best fit for you and the client. Options include:
• Charging by the hour. This is just as it says; the client is charged for each hour you work for them.
• Charging a retainer. You may find it easier to obtain a retainer from the client which guarantees them a certain number of hours service from you which they can use when they need them.
• Charging by subscription. One of the easiest methods of charging for your services is to use a subscription system which involves the client paying a set amount each month or year for an agreed level of service.
These are just some of the charging methods you can consider.
If you speak to any professional web design agency they will tell you how vital their services can be; you can learn more here. This is why agencies should always upsell existing clients with the message that all of the ongoing services we have highlighted are very much needed.

Importing data from non-wordpress mysql database

You have to create an import php file to get the Questions/Answers from a non-wordpress database and bring them into posts in wordpress.

Question Table


/// non-wordpress database connection string here


$results = mysql_query("SELECT * FROM questions");

while ($row = mysql_fetch_assoc($results)) 

    $post_information = array(
	'post_title' => wp_strip_all_tags( $row['question'] ),
	'post_content' => $row['answer'],
	'post_category' =>  array(6,7), // Cat Ids
	'post_date' => date('Y-m-d H:i:s', strtotime( $row['timestamp'] )),
	'post_type' => "post",
	'post_excerpt' => "",
	'post_author' => "admin",
	'post_status' => "publish"
	$post_id = wp_insert_post( $post_information );		
	$filename = "";   ////  Post Thumbnail Image
	$wp_filetype = wp_check_filetype(basename($filename), null );
	$attachment = array(
	  'post_mime_type' => $wp_filetype['type'],
	  'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
	  'post_content' => '',
	  'post_status' => 'inherit'
	$attach_id = wp_insert_attachment( $attachment, $filename, $new_post );
	add_post_meta($post_id, '_thumbnail_id', $attach_id, true);



User Agent Parsing with PHP

Tobie Langel’s ua-parser, a great library which provides simple UA parsing in PHP, JavaScript and Python.

<?php require_once 'uaparser.php';

$parser = new UAParser();
$result = $parser->parse($ua);

echo '<pre>';


Mistserver Manager Login

Find more libraries here...