Thursday, December 20, 2012

PHP Script Execution Nature, A Problem and Solution

Do you know that a php script cannot be executed simultaneously on a single server. Even another script which is included with a executing script also becomes unavailable for execution or being included with other script. Usually a php script with complex algorithms and multiple mysql operations takes approximately 0.005 seconds for completing execution. For usual scripting with some mysql operations and an limited amount of users, the execution nature of apache server (PHP) is perfect. But, suppose, if a script has single or multiple API request to remote servers, then it will take some extra seconds to accept the reply. By the mean time other requests will be queued and will be processed while the script becomes free.

Recently, I have created a script which has more than 25 API requests and requires around 1-2 minutes for completing the whole execution. As the script has some dependencies over some universal scripts of my application, so I needed to change something to make the system always accessible for other users. First thing came to mind was to divide the whole execution and run it on multiple execution to make sure it frees the related scripts for other users for some while. I have used a Session Variable ($_SESSION) where I have put all information required for requesting API request. For every execution of the script, now it sends only a single API request, and then frees the script and redirect to the same script for rest of the requests.

Friday, October 12, 2012

Enable mod_rewrite on apache2 server in Ubuntu

Open terminal write the following codes:

sudo a2enmod rewrite

sudo gedit /etc/apache2/sites-available/default


After executing the second code, a text editor will be open. Find the following code:

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


Edit and change like below:

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all


Then restart apache

sudo service apache2 restart

-That's all.

Increase Maximum Memory Allocation Limit without changing in PHP.INI

Add the following code in your php code if you want to increase maximum memory allocation for any of your specific script which execute to create or modify bigger graphical or other types of files.

ini_set('memory_limit','800M');

800M represents 800 megabytes.

Wednesday, September 12, 2012

Need More Execution Time without Changing PHP.INI

Sometimes it is required to execute multiple commands in a single script that requires more time than usual. We can edit and increase execution time limit from "php.ini" to avoid termination of execution because of outrun of allowed execution time limit. Where increase is only needed for some specific functions or scripts it is unnecessary to change php.ini file. We can easily add more execution time by adding following line before the bigger time consuming functions/codes:

set_time_limit(120);

Code displayed above is defining 120 seconds as a limit of execution time.

Thursday, August 9, 2012

Database Design Best Practices - part 1

Never create multiple tables for storing similar information.

Suppose, you are going to make an inventory software for a shop where you will need to store purchase, sales and transfer information. You have two choices.

One is to create multiple tables for "purchase", "sales" and "transfer" information.

Second is to make a common table for every transaction of products for all of the given type of transactions.

Second is better.

Example:

Bad Practice
table: purchase (pur_id, date, order_by)
table: sales (sales_id, date, order_by)
table: transfer (tr_id, date, order_by)

Best Practice
table: orders (id, date, order_by, order_type)

(Here, bracketed elements are the names of attributes or fields of the table.)

Wednesday, August 1, 2012

"Live Security Platinum" Malware Problem and Step by Step Solution

Recently, I have faced some problem regarding a virus named "Live Security Platinum". It comes to my pc automatically while browsing unknown websites. It appears as following image at desktop:


If you get similar message in your pc, never click on the bubble, not even (x) or settings icon. Wherever you click, it will start a window where you will see a list of infected files of you computer and Live Security Platinum will stop all other executable files and make great damages on them.

If you have done the mistake and clicked on it, just don't wait, restart you computer as soon as possible. After restart, go to Start>All Programs>Live Security Platinum(folder, don't click at it's executable file) then click right button of your mouse keeping the cursor on Live Security Platinum's executable file and select "Open File Location". Delete all files at that location and then uninstall the software from "Program Files>Programs & Features".


Simulation of Link State Routing Algorithm Using PHP

Link State is one of the main routing protocols. Purpose of any routing protocols is to dynamically communicate information about all network paths used to reach a destination and to select from those paths, the best path to reach a destination network. Link state algorithm selects routing paths with lowest costs that are calculated using a distance metric iteratively checking them from each node. 

 
A link-state routing protocol is one of the two main classes of routing protocols used in packet switching networks for computer communications (the other is the distance-vector routing protocol). Examples of link-state routing protocols include OSPF and IS-IS.
The link-state protocol is performed by every switching node in the network (i.e. nodes that are prepared to forward packets; in the Internet, these are called routers). The basic concept of link-state routing is that every node constructs a map of the connectivity to the network, in the form of a graph, showing which nodes are connected to which other nodes. Each node then independently calculates the next best logical path from it to every possible destination in the network. The collection of best paths will then form the node's routing table.
This contrasts with distance-vector routing protocols, which work by having each node share its routing table with its neighbors. In a link-state protocol the only information passed between nodes is connectivity related.
Link state algorithms are sometimes characterized informally as each router 'telling the world about its neighbors'. 


Pseudo-code of Link State Algorithm is presented below:
  1. Initialization
  2. N’ = u
  3. For all nodes v
  4.     If v is a neighbor of u
  5.         Then D(v) = c(u, v)
  6.     Else
  7.         D(v) = µ
  8. Loop
  9. Find w not in N’ such that D(w) is minimum
  10. Add w to N’
  11. Update D(v) for each neighbor v of w and not in N’
  12.     D(v) = min( D(v), D(w)+c(w,r) )
  13. /*
  14. Least path cost to w plus cost from w to v */
  15.  Until N’=N


Link State algorithm is implemented using PHP with Html and Javascript interface. Below I am presenting the implementation.


Download Script: http://dl.dropbox.com/u/47625598/linkstate/index.php

Wednesday, July 11, 2012

Apache Conflicts with Skype: Step by Step Solution

Problem:
Apache doesn't start and shows "Busy".

Description:
After installation of WAMP or XAMPP server, sometimes apache doesn't start. But other services like mysql-server or php are running perfectly. But everytime, it is showing "Busy" as warning and doesn't start when apache is commanded to "start".

Reason:
Every program uses a different port number to run on computer. Some port numbers are allocated for a specific program. Port number 80 is default for webservers. Apache is webserver and it uses "80" as default port number. If this port is already being used by another program, then it will show an warning "Busy" and cannot be started when apache is commanded to start.


Solution:
Try to find out the program which is using port number "80" and quit it. Usually "Skype" uses port number 80 as an alternative port. It is possible to make that port available without quitting "Skype".

From skype toolbar, go to Tools > Options > Advanced Settings > Connection. Then un-check Use port 80 and 443 as alternatives for incoming connections.


Friday, May 4, 2012

PHP Coding Pro: Disable Notice of Undefined Variable in WampServer...

PHP Coding Pro: Disable Notice of Undefined Variable in WampServer...: Yesterday I had to lose a couple of hours to solve a simple problem for my newly installed wamp server. When I tried to open my projects cr...

Disable Notice of Undefined Variable in WampServer

Yesterday I had to lose a couple of hours to solve a simple problem for my newly installed wamp server. When I tried to open my projects created using PHP in browser, they were looking good except a list of warnings. This warning is being displayed because of use of some variable that were not defined before. It was displaying something like this: "Notice: Undefined Variable in line 60". As, I cannot edit all of my projects' scripts, so I planned to disable this warning. But, I don't want to disable the other PHP error messages, only warnings/notices.

Found a simple and easy solution. It can be solved by replacing the line "error_reporting = E_ALL" by "error_reporting = E_ALL & ~E_NOTICE" at php.ini (php configuration file). But, after trying to edit a php.ini at "wamp/bin/php" I didn't see any changes. What happened, after some trial I got that, I am editing the wrong file. I should've edited php.ini from "wamp/bin/apache/Apache2.2.21/bin/". Edited that file and got the result at last. It's really confusing when there are multiple same files in different subfolders of a same root folder.

Sunday, March 11, 2012

Color- Synchronization between html and gd library

Is there any differences in color codes in php-gd library and html? When I pick a color and send it to script, it doesn't look same. I need to find out a procedure to make them synchronized.

Oh, I got a point, ##F0F8FF is a hexa-decimal representation of color, which is widely used in html and supported by all browsers. But, I should use different format of color code except hex which is similar to gd library's way of color recognition. Usually GD makes color from intensity of green, red and blue. I can also use this same format for html by using rgb($red, $green, $blue) instead of hex. Hope, it will help me.

Now, I have to think about dynamic use of this format which will come directly from my database. I think, if I use '-' as delimiter then it will be perfect. I will generate html and gd script from the same think as they require by deleting '-' and using the real values.

This way I could solve my problem.

Saturday, March 10, 2012

FFMPEG-PHP! Made me tired

It is almost two weeks, I have started working on something which requires ffmpeg-php extensions. Downloaded some classes, none of them worked, because I was using windows platform, and ffmpeg decoders still don't like to work with windows. Oh, I have to go back linux again. Sarmed Vai suggested me to test linux at Oracle VirtualBox. That helped me a lot, because I had to install, re-install and uninstall different distributions of linux, direct installation could make my pc gone-forever.

Ubuntu couldn't help, it's not completely perfect for server things, but for personal use, it's awesome. And there is another version may be exist which is for making a server, but I had no cd of that. Gave up after multiple trial, then downloaded CentOS (again suggested by Sarmed Vai).

I had to install apache (httpd), php, mysql etc, and also ffmpeg, I am now going to tell you how I tried to install ffmpeg in CentOS.

Tried the following commands at terminal:

cd ~
mkdir ffmpeg
wget http://dfn.dl.sourceforge.net/sourceforge/ffmpeginstall/ffmpeginstall.3.2.1.tar.gz
tar zxf ffmpeginstall.3.2.1.tar.gz
cd ffmpeginstall.3.2.1
./install

I saw many things on screen, but don't know if it is really done. Just tested some functions, but couldn't see any progress. I quit. I did this procedure for multiple times, and in different distros. Now, I should to wait for a help.

I think I have to think about windows again. Let me do some search in google, found some posts, but not sure if they can help me.

It didn't help, followed the complete procedure, but it's not working. It's a nightmare for me, I lost lots of hours for doing this, and could not make it, Dhaaaaatt....

Thanks to Muntasir Rashid, he just have given me a ffmpeg-php enabled hosting. Just checked a function for making a thumbnail from a video, and wow! it is created successfully. Now, I have to make a video from set of pictures.

Got another way to install ffmpeg-php in my CentOS server.

Already did the following procedures:

1. Added a file: "/etc/yum.repos.d/dag.repo" with following contents to add a 3rd party yum repository:

[dag]
name=DAG RPM Repository
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

2. Ran following commands:

rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
rpm --import RPM-GPG-KEY.dag.txt

3. Tested the setup using the following command:

rpm -q gpg-pubkey-*

Got some multiple line output like: gpg-pubkey-e8562897-459f07a4

4. Then updated "yum" by the command: yum update
5. Installed ffmpeg using the command: yum install ffmpeg ffmpeg-devel
6. Downloaded and installed ffmpeg-php using the following command:

wget http://sourceforge.net/projects/ffmpeg-php/files/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2/download

tar -xjf ffmpeg-php-0.6.0.tbz2

cd ffmpeg-php-0.6.0

7. Some geniuses think there is an error in the file "ffmpeg_frame.c", I replaced all "PIX_FMT_RGBA32" patterned text into "PIX_FMT_RGB32". Hope, it will work.

8. Then I had to configure ffmpeg-php using the following command:

phpize
./configure && make
make install

Here, I had to fall in a situation. phpize command doesn't work. I tried to install php-devel by the command "yum install php-devel" and after it's installation, "phpize" command worked.

Then, I had to add the extension to /etc/php.ini by adding the following line:

extension=ffmpeg.so

Now, I have to check if it really works.

Alhamdulillah, it works.

Testing Webserver (httpd) at VirtualBox

Now, my challenge is to browse websites hosted in CentOS which is running in a VirtualBox window. Already installed httpd, php, mysql, perl etc. and they are working fine. I could manage to test a script using text based web browser lynx.

Now, I am going to try from host pc using graphical browser. I'll have to define a ip address at guest CentOS then try to browse it.

Before starting, I have to change network settings of virtual box for CentOS installation. I changed it at virtualBox>Settings>Network>Attached to, choose "Host-only Adapter" then clicked "Ok". Now it's ready for doing the rest.

I forgot the way how to change ip, searching, but finding nowhere. What happened!! Better keep searching my notes of my B.Sc networking classes. I don't know where to find them. Wow, I have found those notes, but they are about Red Hat, I have to make them useful for my current CentOS.

Yeah, I can now browse hosted files from guest pc. Let me tell what I have done:

First, I have checked virtual host-only network ip address of host pc.
Then, I have edited ip address of guest "centos" by the following command prompt codes:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

pressed "i" for inserting text into the script, started from at end of the lines there. Added these following lines:

BOOTPROTO=static
IPADDR=192.168.56.5
NETMASK=255.255.255.0
GATEWAY=192.168.56.1

For your information 192.168.56.1 is the ip address of host-only network card (virtual).

Then restarted network by the following command prompt code:

service network restart

Then, went to my graphical browser at host, and got the default centos-apache page. And also could browse my hosted files.

Friday, March 9, 2012

Real approach to install php/mysql on linux-apache web server

Hi, I have just found out that working on lampp in linux is not a real approach of working on PHP based software development. Recently, I need to use some multimedia encoder/decoders to compile some of my scripts, but lampp could not help me. We usually use lampp to install the whole working environment fast and in one click, but when we need some extra things to be included with this, it may not help and consume time to start.

I am using CentOS to make a real web server (for test scripts), it has a nice built in package manager YUM. I have already installed "Apache 2" for creating web server. It was easy and fast, apache (httpd) comes with centOS disks as default. I used the following line to install it.

yum install httpd

Then, I had to install php, php command line, perl, mysql to make the server ready for lamp development environment. This installation process required Internet connection and I used following line to install the whole thing.

yum install php php-cli mysql

It automatically searched all dependencies and the mirror from which they will be installed.

I didn't check the environment yet, but hope, it will help me fine.

Tuesday, February 28, 2012

Installing XAMPP/LAMPP in Linux

For Ubuntu:

Start Terminal.

If you have already updated you apt repository then enter write "apt-get install lampp" in terminal and press enter. XAMPP will be installed automatically.

But, if you don't have updated apt repository, then write "apt-get update" in terminal and press "Enter".

Sometime it becomes difficult to install software from Bangladesh. For solving this problem go to "System Settings" from start menus. Then, go to "Software Sources" from Settings menus. Click "Ubuntu Software" tab. change the source of Download from "Download From" drop-down filed. Choose Main Server to avoid problem of online software installation using "apt-get". Don't forget to update apt by writing "apt-get update" at terminal and pressing enter.

For CentOS:

First check if your "wget" command is installed for the system. If not, login to terminal as root and then write "yum install wget" and press enter. Then press y and enter to approve installation of "wget".

Then, download installation file for XAMPP.
write "wget http://www.apachefriends.org/download.php?xampp-linux-1.6.8a.tar.gz" and press Enter, installation file will be stored in current file directory.

After the download is complete, install XAMPP using the command: tar xvfz xampp-linux-1.6.8a.tar.gz -C /opt

If you want to start XAMPP at the start of the machine Command the following commands:

lvl=`egrep :initdefault: /etc/inittab|cut -d: -f2`

cd /etc/rc.d/rc${lvl}.d

ln -s /opt/lampp/lampp S99lampp

ln -s /opt/lampp/lampp K01lampp


Starting, Restarting or Stopping XAMPP Server:

First go to root directory: cd /

Then for starting XAMPP server: opt/lampp/lampp start

for re-starting XAMPP server: opt/lampp/lampp restart

for starting XAMPP server: opt/lampp/lampp stop

Tuesday, January 24, 2012

Software Engineering Tools and Their Applications

Turbo C++
Type: Compiler/IDE
Description: Turbo C++ was a C++ compiler and integrated development environment and computer language originally from Borland.
Application: Turbo C++ is used for compiling codes written in C/C++ programming language into binary code.

Java Compiler (javac)
Type: Compiler
Description: Java is a compiler developed by Sun Java Corporation. Java is an Object Oriented Programming language.
Application: Javac is used for compiling codes written in Java programming language.

GNU Debugger
Type: Debugger
Description: The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger for the GNU software system.
Application: It is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java and partially others.

Intel Debugger
Type: Debugger
Description: The Intel Debugger (IDB), developed by Intel Corporation.
Application: Intel Debugger provides support (at various levels depending on compiler product) for debugging programs written in C, C++, and Fortran.

DBG
Type: Debugger
Description: Open source Debugger.
Application: DBG is used for debugging programs written in PHP programming language.

Concurrent Versions System
Type: Version Control Software
Description: The Concurrent Versions System (CVS), also known as the Concurrent Versioning System.
Application: CVS is a client-server free software revision control system in the field of software development.

Apache Subversion
Type: Version Control Software
Description: Apache Subversion (often abbreviated SVN, after the command name svn) is a software versioning and a revision control system distributed under a free license.
Application: Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).

Yoxel
Type: Requirement Analysis Tool
Description: ArgoUML is developed by Dzmitry Churbanau during the Google Summer of Code 2007 program.
Application: Yoxel is used for analysis of software requirements. It’s ArgoPDF feature helps to generate report in PDF format.


OpenPSA
Description: OpenPSA is a management software package for running consultancies and software companies.
Application: OpenPSA is used for managing a software development project. It provides product database, hour tracking, invoice tracking, reporting etc.

Netbeans
Type: IDE
Description: Oracle Corporation developed Netbeans IDE.
Application: Supports all major programming and markup languages like Java, C/C++, Python, Ruby, PHP, HTML, XML etc.

Eclipse
Type: IDE
Description: Open source IDE.
Application: Supports all major programming and markup languages like supports C/C++, Java, PHP, COBOL, Ruby etc.


ASP.NET MVC Framework
Type: Framework
Description: ASP.NET is a pattern base software development framework.
Application: ASP.NET MVC framework is used for developing scalable softwares in .NET platform.

Zend Framework
Type: Framework
Description: Zend is a pattern base web application development framework developed by PHP Company.
Application: Zend is a MVC framework is used for developing scalable softwares in .PHP platform.

AgroADML
Type: Design
Description: Software Architecture Design Tool
Application: ArgoADML is a diagramming tool for graphycally editing architectural descriptions represented in ADML (Architecture Description Markup Language).

COCOMO
Type: Cost Estimation Software
Description: The Constructive Cost Model (COCOMO) is an algorithmic software cost estimation model developed by Barry W. Boehm.
Application: COCOMO is used for estimating cost of a software development project using a basic regression formula with parameters that are derived from historical project data and current project characteristics.

JIRA
Type: Issue/Bug Tracking Software
Description: JIRA (/ˈdʒɪərə/ jeer-ə)[2] is a proprietary issue tracking product, developed by Atlassian.
Application: Jira is used for bug tracking, issue tracking, and project management.

Reference
1. http://wikipedia.com
2. http://tigris.org