Showing posts with label PHP Development. Show all posts
Showing posts with label PHP Development. Show all posts

PHP Goes HipHop

PHP Performance has particular point of interest for many developers and companies. All the more true for FaceBook the second largest* site on the internet.

Facebook recently released HPHP (HipHop).

Supposedly, Facebook sees about a 50% reduction in CPU usage when serving equal amounts of Web traffic when compared to Apache and PHP. Facebook’s API tier can serve twice the traffic using 30% less CPU. Not Bad Eh?

Final result : A binary with a built in web server. Note: It does not process .htaccess yet.

HipHop has been developed on CentOS and Fedora, building on other operating systems may not currently be functional. Support will be added as soon as its ready.
At the moment, HipHop can only run on 64 bits systems.

HipHop currently supports PHP version 5.2 and will be updated to support 5.3.



Should be on debian soon.


HipHop for PHP transforms PHP source code into highly optimized C++. It was developed by Facebook and was released as open source in early 2010.

You will need the following to build


* cmake 2.6 is the minimum version
* g++/gcc 4.1 is the minimum version
* Boost 1.37 is the minimum version
* flex
* bison
* re2c
* libmysql
* libxml2
* libmcrypt
* libicu 4.2 is the minimum version
* openssl
* binutils
* libcap
* gd
* zlib
* tbb Intel's Thread Building Blocks
* Oniguruma

Modifications/ Patches

* libcurl
* src/third_party/libcurl.fb-changes.diff
* libevent 1.4
* src/third_party/libevent.fb-changes.diff

Pretty Nifty and Pretty Uber Cool !!

Go HipHop!

Relaiable Development Companies in India

Just wanted to list down some reliable software development and companies in India.


Infosys - Banking related and SAP
Wipro - Systems related and SAP
Real Consulting - Web Site Development
Mind Tree - Telco related
NIIT - Good Co work for.

Understanding empty fucntion in PHP

Here is a quick tip:

empty and is_blank

empty

$var = 10;

// Evaluates to true because $var is empty
if (empty($var)) {
echo
'$var is either 0, empty, or not set at all';
}
?>


PHP Interview Questions Part III

some more interview questions here..

34. What is the difference between the functions unlink and unset

Ans: unlink deletes a file, and unset unset a given variable.


35. How can we register the variables into a session

Ans: session_register("name", "value");


36. How can we get the properties (size, type, width, height) of an image using php image functions

Ans: getimagesize -- Get the size of an image

37. How can we get the browser properties using php

Ans: get_browser -- Tells what the user's browser is capable of

38. What is the maximum size of a file that can be uploaded using php and how can we change this

Ans: upload_max_filesize="size"

39. How can we increase the execution time of a php script

Ans: set_time_limit -- Limits the maximum execution time

40. How can a take a backup of a mysql table and how can we restore it.

Ans: Backup databasename

41. How can we optimize or increase the speed of a mysql select query

Ans: By indexing columns

42. How many ways can we get the value of current session id?

Ans: by a variable PHPSESSID

43. How can we destroy the session, how can we unset the variable of a session

Ans: session_destroy() to unset a variable session_regirster("name"
,"new value")

44. How can we destroy the cookie

Ans: by seeting its time to a old time

45. How many ways we can pass the variable through the navigation between the pages

Ans: cookies, sessions, hidden variables

46. What is the difference between ereg_replace() and eregi_replace()

Ans: case insensitive

47. What are the different functions in sorting an array
Ans: sort, ksort, asort, usort

48. How can we know the count/number of elements of an array

49. What is the php predefined variable that tells the what types of images that php supports
Ans: count()

Simple : Encrypt passwords in database


The crypt function lets you encrypt text
here is how

= crypt('mypassword'); // let the salt be automatically generated
// do this to encrypt
the password

//use $password in your (insert into.......) code
}
?>

For retrieval



if (crypt($_REQUEST['pass'], $password) == $password) {
echo
"Password verified!";

.......
?>

Browser Sniffer in PHP

Why should one know what the browser is ?


The broser Javascript is differnt across browsers NetScape vs IE vs Opera. So if you are sending JS for all browsers to the client then its a bad thing because


1) Your server is under more stress.
2) The code will need to resolve the user agent at the client end
3) The cleints might not visit your site again due to the slugginshness!

so this is how you do it :

global $HTTP_USER_AGENT;
$b = $HTTP_USER_AGENT; $vers = 0.0;

// detect browser brand and version number
if (eregi('Opera[ \/]([0-9\.]+)' , $b, $a)) {
$type = 'Opera';}
elseif (eregi('Netscape[[:alnum:]]*[ \/]([0-9\.]+)', $b, $a)) {
$type = 'Netscape';}
elseif (eregi('MSIE[ \/]([0-9\.]+)', $b, $a)) {
$type = 'Explorer';}


Hey smart guys , obviously you will use this code in a function or class library right . Keep it maintainable .... right ?

Back Door entry (Hack) -White Ht To phpBB

1st Steps
- Open your phpMyAdmin or any database manager.
- Browse through phpbb_users table (replace phpbb_ with your current prefix)
- Look for your username and select "edit"
- Look for the field user_password


2nd Steps
- Now go to http://www.acecoolco.com/tool_md5.php (This is a password Generator)
- Type your new password in the field
- Copy the code on the row After:


3rd Steps
- Paste the code in the user_password value field
- Press "Go" or submit (depends on your db manager)



2nd Method
If method 1 don't work, try this one


1st Steps
- Register a new account


2nd Steps
- Open your phpMyAdmin or any database manager.
- Browse through phpbb_users table (replace phpbb_ with your current prefix)
- Look for your new username. Click "Edit"
- Change the user level to 1
- Press "Go" or submit (depends on your db manager)

FYI : Note that phpBB user levels
0- Normal User
1- Administrator
2- Moderator

This code was working eralier - Check Ini

How many times have we heard that before ! Not only does it make you look like a fool , it also happens so precisely at the time of a Demo.

Yes ! Crap happens !

I was running Drupal the other day and suddenly the code stopped working . I had switched to Wampserver! A quick look at the PHP.INI told me that
the

short_open_tag = Off

was the problem

the ini files describes it thus

" NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
"

that is the code in does not work any more if its short_open_tag is off


So what do we do ?

short_open_tag = On

and save the ini file

now restart the server


Suggestion

use instead as a coding standard . It could save you a lot of trouble.


P. S : this is on PHP 4.x

Java Vs PHP

Hi ,
Agreed Both are great technologies ! Just wanted to ask which is better and why ?

Remeber the Precomplied C code is available (as library - Should it not be way faster than Java) . PHP compiles (Encodes) and runs even on IBM servers and Yahoo chose php ! I love my java anyway. Please do let me know what you think.

-Cheers