Today's Question:  What are you most afraid of as a programmer?        GIVE A SHOUT



  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 a...


  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 default When 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 itself Add Generator function getLinesFromFile($fileName) { if (!$file...

9,832 0 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 wr...


  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...

6,021 0 1          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 ...

13,871 2 4          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...

7,056 0 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 ...


  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 und...

10,617 0 1          PHP://INPUT IO INPUT