Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Thursday, September 7, 2017

PHP popen() Function

popen in php

Parallel processing in PHP Using popen() Function


Since PHP does not offer native threads, we have to get creative to do parallel processing.
There will be scenarios where PHP takes much time to complete a task. Example scenarios are attaching a large file and and sending an email, or processing a large video file 
to make thumbnails. Imagine  a user having to wait until PHP finishes the all that job.

All the heavy work might being going on at the server. 
But, if a user doesn't see any activity on a page for some time, they might think that the page is not working and leave the page.  In such cases, we can make use of a background process.


Example of popen as a Async processing


Make popen as synchronous

The below code will wait until child process completed.
echo date("h:i:s");echo "\n";
$ph = popen('php ' . $commandName , 'r') or die($php_errormsg);
while (! feof($ph)) {
$s = fgets($ph) or die($php_errormsg);
}
pclose($ph) or die($php_errormsg);
echo date("h:i:s");echo "\n";

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

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


Friday, February 3, 2017

Check Mod Rewrite Enabled or not in Apache

To check either mod rewrite enabled or not in Apache

Check mod rewrite is enabled or not

1. Create sample.php file in localhost root folder with below content

print_r(apache_get_modules());

output check for mod_rewrite

2.To check .htaccess is working keep the below code in .htaccess
RewriteEngine On
RewriteRule ^.*$ test.php