Friday, September 1, 2017

Configure Apache web server for Python on Windows

Run Python script as CGI program with Apache2.4 in Windows


1. Install Python and Apache

Python: http://python.org/download/.

Apache: http://httpd.apache.org/download.cgi


2. Configure Apache to run Python CGI

The next step is to edit ‘httpd.conf’ apache configuration file located in the apache
install directory in the conf directory.

Uncomment the below line
#LoadModule cgi_module modules/mod_cgi.so

After Uncomment
LoadModule cgi_module modules/mod_cgi.so

Search the httpd.conf file for the line

Options Indexes FollowSymLinks

Add ExecCGI to the end of the line. After adding total line looks like below

Options Indexes FollowSymLinks ExecCGI

Next, search for the following:

#AddHandler cgi-script .cgi

Uncomment this line by removing the # in front of the line,
and add a .py to the end of the line. The new line should look like this:


 AddHandler cgi-script .cgi .py



Search for the line: ScriptAlias /cgi-bin/ /whatever-path/ – when you find it,
comment out the line: that is add a # in front of the line:
(or)Other wise add the below line

ScriptAlias /cgi-bin/ "C:/Apache2.4/cgi-bin/"


3. Restart Apache


4. Run the sample python file

Here is an example assuming Python is installed in the C:\Python27 location



Save this file as test.py to your htdocs folder under your apache installation directory.
Open your web browser and type in your apache host
(and :port if the port is something other than 80) followed by test.py,
for example:   http://localhost/test.py

PHP Array insert, delete, view operation using php array functions

PHP Array Functions

Insert the array element, View the array values and delete the array value using php array functions
Function Name Description
array_search() Searches an array for a given value and returns the key
array_splice() Removes and replaces specified elements of an array


Sample php array functions code



Friday, August 4, 2017

Asterisk Call Originate Action Using Pami

asterisk

What is Asterisk?

Asterisk is an open source framework for building communications applications. Asterisk turns an ordinary computer into a communications server. Asterisk powers IP PBX systems, VoIP gateways, conference servers and other custom solutions. It is used by small businesses, large businesses, call centers, carriers and government agencies, worldwide. Asterisk is free and open source.

About PAMI

PAMI means PHP Asterisk Manager Interface. It is an OOP client for the Asterisk Manager Protocol, implemented in PHP.

About PAMI Features

  • TCP and TLS connections.
  • Event Driven (the framework will dispatch events to your listener).
  • Lightweight, easy of use, and useful.
  • Supports synchronous and asynchronous events (Actions with Responses, and 
  • Responses with Events associated).
  • Supports SMS via VGMS boards.


Tuesday, July 18, 2017

Getting Started with Redis in PHP

What is Redis?

Redis created by Salvatore Sanfilippo is an open source, in-memory data structure server with advanced key-value cache and store, often referred to as a NoSQL database. It is also referred to as a data structure server, since it can store strings, hashes, lists, sets, sorted sets, and more.

The essence of a key-value store is the ability to store some data, called a value inside a key. This data can later be retrieved only if we know the exact key used to store it.

Usage of Redis

  • Caching can be used in the same manner as memcached.
  • Leaderboards or related problems.
  • Counting stuff.
  • Real time analysis.
  • Deletion and filtering.
  • Show latest item listings in your home page.

Install on Windows

Now, let us check how to set up Redis PHP driver.

You need to download the phpredis from github repository https://github.com/nicolasff/phpredis. Once you’ve downloaded it, extract the files to phpredis directory.

extension = redis.so

Connect to Redis Server


Monday, July 17, 2017

Inter Process Communication Using PHP ,ZeroMQ AND React/ZMQ

push the external changes to existing web pages

The above diagram shows the any external php file or database layer changes has happen should be notify to all our web client. We can able to achieve this using React/ZMQ

Requirements

ZeroMQ

All Our client web pages will be listening to port 8080 for incoming WebSocket connections...but how will it also get updates from another PHP script or another server process event. Enter ZeroMQ. We could use raw sockets, like the ones Ratchet is built on, but ZeroMQ is a library that just makes sockets easier. install zmq

React/ZMQ

Ratchet is a WebSocket library built on top of a socket library called React. React handles connections and the raw I/O for Ratchet. In addition to React, which comes with Ratchet, we need another library that is part of the React suite: React/ZMQ. This library will bind ZeroMQ sockets to the Reactor core enabling us to handle both WebSockets and ZeroMQ sockets. To install, your composer.json file should look like this:

To Run the above application go to root directory "push" run below command to run the web socket connection on server side
php bin/push-server.php
Run the : "push\src\MyApp\clientwebpage.html" which connect to web socket listen to the specified category

PHP ZMQ extension Installation in Apache 2.4 & php 5.6


PHP ZMQ extension we will look at how you can easily distribute work to background processes, provide flexible service brokering for your next service oriented architecture, and manage caches efficiently and easily with just PHP and the ZeroMQ libraries. Whether the problem is asynchronous communication, message distribution, process management or just about anything, ZeroMQ can help you build an architecture that is more resilient, more scalable and more flexible, without introducing unnecessary overhead or requiring a heavyweight queue manager node..

Installing ZMQ in Windows

Required Softwares Apache 2.4 & PHP 5.6
  1. Download the zmq php extension from following url depends up on the installed php version
    url: ZMq Download Url
  2. Extract the folder
  3. Copy the php_zmq.dll to php/ext directory
  4. Then copy the libzmq.dll to the php/ root directory
  5. Add below line in php.ini file : extension=php_zmq.dll

Friday, April 7, 2017

Defining a HTML template to append using JQuery

Append Dynamic content to html template using Jquery

If we want to append the dynamic content to html template using jquery below will be the simple solution