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,163 0       EXAMPLE PHP SESSION SESSION TIMEOUT


  New features in PHP 5.5

Just a few days ago, the PHP official website was redesigned. It seems we directly go from Web 1.0 era to Web 2.0 era. In addition to this new change, PHP 5.5 was also released. Some new features are added in this release. Here we summarize some of them.Enable OPCache by defaultWhen installing PHP 5.5, the Zend OPCache will be compiled as OPCache by default and OPCache is enabled by default.Some changes to the language itselfAdd Generatorfunction getLinesFromFile($fileName) { if (!$fileHandle = fopen($fileName, 'r')) { throw new RuntimeException('Couldn\'t open file "' . $fileName...

11,303 0       NEW FEATURES PHP 5.5 GENERATOR


  PHP buffer: output_buffering and ob_start

buffer is one piece of memory section, it is usually 4Kb in Linux. It is mainly used between different devices with different speed or different priorities. With buffer, the waiting time between different processes will be reduced. Here is one simple example, when you type something in a text editor, every time when you type a character, the operating system will not write it to the disk directly, instead it will write it to buffer first When the buffer is full, the data in the buffer will be written to disk. But when you call flush(), the data in the buffer will be written to the disk immedia...

18,771 1       PHP BUFFER OUTPUT_BUFFERING OB_START


  A trap about PHP random number

The method to get random number in PHP is very simple, we only need to use rand() function.int rand ( int $min , int $max ) One function call can return the random number in a specified range. But in fact, the random number in computer is actually pseudorandomness, generally to increase the randomness, we may set a random seed before calling rand().void srand ([ int $seed ] ) According to other language features, we should pass a time value as a parameter to the srand() function, generally we may pass millisecond or microsecond. Starting from PHP 4.2, srand() will be automatically called whe...

11,507 0       PHP RAND SRAND MT_RAND


  PHP to get access token for Sina Weibo app

Previously I wrote two articles about getting access token for Facebook and Twitter apps using PHP. Today I will write one more article about getting access token for Sina Weibo app using PHP.OAuth 2.0 is now the authorization mechanism of Sina Weibo API. The API authorization process is similar to the process of Twitter. It has basically two steps: 1. Authorization; 2. Get access token.1. Create an app.I hope you know how to create an app in Sina Weibo now. If not. You can access this page and it will guide you on how to create the app. After you creating the app. You should write down the Ap...

18,483 2       PHP ACCESS TOKEN SINA WEIBO


  PHP advisory file lock : flock

When we process a file in PHP, we may often need to acquire a lock so that other scripts cannot edit the same file at the same time. There is a flock() function in PHP which can help us lock the file we want to process. But there is one issue we should take care.Recently, ffb encountered one issue while he was trying to lock a file handle. The codes are below:$filename = "/tmp/lock.txt";    $fp = fopen($filename, "r+");  if (!$fp) {      die("open failed.");  }    i...

8,153 0       PHP FLOCK() ADVISORY LOCKING


  PHP to get access token for Twitter app

Previously we wrote an article about getting access token for Facebook app--PHP to get access token for Facebook app. Today we will introduce how to get access token for Twitter app using PHP.Since now Twitter is also using OAuth 2.0 to allow some web apps to access some users information on behalf of one user. They provided some APIs for developers to easily get them integrated with their own websites. The first step to get all these done is how to get the access token, the access token seems like the password to one user's account on Twitter.First, we need to download the SDK, in this articl...

16,061 0       PHP TWITTER OAUTH ACCESS TOKEN


  php://input in PHP

When using xml-rpc, server side will get the data from client with php://input method instead of $_POST. Hence today we will discuss php://input.PHP official manual has below explanation to php://input:“php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype=”multipart/form-data”.Here we understand the above statement from 3 aspects:Read POST dataCannot use multipart/form-data typephp://input...

34,867 0       PHP://INPUT IO INPUT