Showing posts with label windows. Show all posts
Showing posts with label windows. 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";

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

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

Thursday, November 17, 2016

mongodb install windows

mongodb install windows

Download the latest production release of MongoDB from the MongoDB downloads page.

Click on .msi file and follow the instructions.

mongo Db

To Start the Mongodb server

Open an Administrator command prompt. Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator. Go to Mongo db installed directory.
sy: mongod --dbpath="path to db" --port=27017
 Example: mongod --dbpath=d:\mongodb\ --port=27017

mongod ------ Command
dbpath  --- specify the database storeing path
port --- port number default port (27017)




Connect to the Mongo Db server using command prompt

Using below command we will able to connect to mongo server from command prompt in windows

sy : mongo --port=27017
Example: "C:\Program Files\MongoDB\Server\3.2\bin\mongo.exe