Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PHP


  What you may not know about PHP session

When we access one website, the site usually should have a mechanism to keep track of the status of the user on the site. There are a few mechanisms supported by many server side languages to help track user status such as session and cookie.Today we will talk about session, when creating a session, we need to keep track of many data, besides user data, we also need to tell the server what is the timeout of the session so that we can garbage collect the session data which should not be stored anymore. How do we implement a reliable session mechanism?In PHP, we are often told that we can change...

10,250 0       EXAMPLE PHP SESSION SESSION TIMEOUT


  The confusing strtotime() function in PHP

Frequently PHP programmers get confused of the use of i month, -1 month, next month in strtotime() function. and hence it leaves some impression to programmer that this function is not that reliable.Let's take one example of strtotime call with -1 month and see why it leaves this impression.date("Y-m-d",strtotime("-1 month"))  // Assume today is 2018-07-31What's the output of above call? The answer is 2018-07-01. Why not 2018-06-30? So people get confused. It appears that this is wrong at first glance, but if think again, this output is reasonable.Below is how the logic worksIt first...

10,023 0       STRTOTIME PHP FIRST DAY OF -1 MONTH


  Node.js: Five Things Every PHP Developer Should Know

I recently started working on a few Node.js applications. Coming most recently from PHP (and Drupal in particular), I found the transition to Node.js to be surprisingly easy. Pleasurable, in fact. But I had to learn to think differently about a few things.Below I list the five things I think every PHP developer should know about Node.js.1. Node.js Is Built On Chrome's JavaScript EngineGoogle's browser, Chrome, has a notoriously fast JavaScript engine called V8. And this JavaScript engine can be cleanly separated from the web browser. Node.js is built on V8. This is one of the main reasons why ...

9,861 0       PHP DEVELOPER FEATURE NODE.JS


  mysql_fetch_array(),mysql_fetch_assoc() and mysql_fetch_row()

In PHP MySQL mannual. There are three functions which need to be clarified for some users who may get confused when choosing which one to use to get the result.mysql_fetch_array() : by seeting the different parameters, there are three ways to return the result set. MYSQL_ASSOC(Result set with field names as the associative indexs.It means you can use the field name as the index to get value of the specified cell). MYSQL_NUM(Result set with field names as the number indices). Or MYSQL_BOTH(you can use both modes to get value of a specified cell).mysql_fetch_assoc():Result set with field na...

9,337 0       PHP COMPARISON MYSQL RESULTSET MYSQL_FET


  Multiple Constructor in PHP

See code:class MultipleConstructor {private $info = ”;function __construct() {$argv = func_get_args();switch( func_num_args() ){default:case 1:self::__construct1($argv[0]);break;case 2:self::__construct2( $argv[0], $argv[1] );break;}}function __construct1($value) {$this->info = $value;}function __construct2($value, $value2) {$this->info = $value . ” ” . $value2;}function get() {return $this->info;}}$a = new MultipleConstructor(‘Value 1′);echo $a->get();$b = new MultipleConstructor(‘Value 1′, ‘Value 2′);echo $b->get();Viola!!!...

9,243 0       PHP CONSTRUCTOR MULTIPLE CONSTRUCTOR


  A trap in PDOStatement::bindParam

First, let's check out below codes:<?php$dbh = new PDO('mysql:host=localhost;dbname=test', "test"); $query = <<prepare($query); $bind_params = array(':username' => "laruence", ':password' => "weibo");foreach( $bind_params as $key => $value ){ $statement->bindParam($key, $value);}$statement->execute();What is the SQL executed finally? Is there any problem with above codes?Many people may think the query executed is :INSERT INTO `user` (`username`, `password`) VALUES ("laruence", "weibo");But the query actually gets executed is :INSERT INTO `user` (`username`, `passwor...

9,236 1       PHP TRAP BINDPARAM


  One reason why mcrypt responds slowly

This morning one colleague came over and talked about one script which used mcrypt responded very slowly, the server configurations are fine. But the reason for the slowness is unknown.Here is one script which reproduces the issue:<?php$dmcryptText = "dummy";$key = "foobar";$size = mcrypt_get_iv_size(MCRYPT_BLOWFISH,MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($size); //Take care $m = mcrypt_ecb(MCRYPT_BLOWFISH, $key, $dmcryptText, MCRYPT_DECRYPT, $iv);var_dump($m);When 20 requests of this script are sent to the server in parallel, the response time of Apache server increases rapidly.The r...

9,163 8       PHP SOLUTION SLOW MCRYPT RESPONSE


  PHP Multithreading – Faking It

PHP doesn’t really support multi-threading per se but there are ways to do “fake” multithreading. Here’s one I saw in the PHPClasses.org newsletter – Multi-thread Simulation.Note that this class is intedend for use on a webserver, as opposed to running PHP scripts from a command line (or similar). Check the end of this post for some alternatives you can try if you’re using PHP as a stand-alone scripting language.Now, I’m going to be lazy and just copy the description of the class from the project page :)This class can emulate the execution of prog...

8,741 0       PHP MULTITHREADING POSSIBLE CURL FAKE SI