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

SEARCH KEYWORD -- PHP



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

   PHP,Multithreading,Possible,CURL,Fake,Si     2011-09-04 23:07:22

  Using PHP sessions across subdomains

By default, PHP uses the 'PHPSESSID' cookie to propagate session data across multiple pages, and by default it uses the current top-level domain and subdomain in the cookie declaration. Example: www.domain.com The downside to this is that the session data can't travel with you to other subdomains. So if you started a session on www.domain.com, the session data would become unavailable on forums.domain.com. The solution is to change the domain PHP uses when it sets the 'PHPSESSID' cookie. ...

   PHP,Session,Subdomain,Availability     2011-12-25 02:36:25

  Why hasn't Facebook migrated away from PHP?

The reason Facebook hasn't migrated away from PHP is because it has incumbent inertia (it's what's there) and Facebook's engineers have managed to work around many of its flaws through a combination of patches at all levels of the stack and excellent internal discipline via code convention and style - the worst attributes of the language are avoided and coding style is rigidly enforced through a fairly tight culture of code review (failing to adhere to the style and "going cowboy" by writ...

   Facebook,PHP,Migration,Bad feature,Codebase     2012-02-24 05:14:23

  Using DateInterval class in PHP

DateInterval is (amongst others) a relatively new addition to the date extension in PHP 5.3. It allows to describe an interval in time, and you can perform actions with that interval. Basically, it allows to calculate with dates in a very easy way, and do even more fun stuff with it.Unfortunately no documentation exists today for DateInterval and friends, but PHP is open-source so you can easily have a peek at the code to see what’s happening under the engine. This is more or less what th...

   PHP,DateInterval,Class,PHP 5.3,Demo     2011-10-21 10:35:54

  Output control functions in PHP

The Output Control functions in PHP allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo and data between blocks of PHP code. These output control functions include ob_start(0, ob_clean(),ob_get_contents(), etc. To be honest, I a...

   PHP,output buffer,relationship,ob     2012-06-15 10:11:58

  jsonSerialize() in extended class

Since PHP 5.4.0, there is a convenient interface JsonSerializable which can be used to indicate that a PHP object can be serialized to JSON object. It has only one method which should be implemented by any class which implements this interface. The method is named jsonSerialize(). It's really easy to serialize an object to JSON object. Here is one example: <?php class ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; ...

   JSON,jsonSerialize,Inheritance,extends     2014-07-26 05:54:00

  Some tricks on PHP session

1. Session timeout problem There is a nuance we found with session timing out although the user is still active in the session.  The problem has to do with never modifying the session variable. The GC will clear the session data files based on their last modification time.  Thus if you never modify the session, you simply read from it, then the GC will eventually clean up. To prevent this you need to ensure that your session is modified within the GC delete time.  You can accomp...

   PHP,Session,Timeout,Solution,Various domain     2015-03-13 07:05:37

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

   PHP,Trap,bindParam     2013-08-29 10:48:55

  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-31 What'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 ...

   PHP,STRTOTIME,FIRST DAY OF,-1 MONTH     2018-08-04 05:49:32

  Case sensitivity in PHP

Case sensitivity in PHP is a bit messy. We recommend that you stick to the case sensitive rule in any language. Here we share some case sensitivity cases in PHP.1. Case sensitive1.1 Variable name is case sensitiveAll variables names are case sensitive, these include normal variables and superglobals such as $_GET,$_POST,$_REQUEST,$_COOKIE,$_SESSION,$_GLOBALS etc.<?php$abc = 'abcd';echo $abc; //Output 'abcd'echo $aBc; //No outputecho $ABC; //No output1.2 Constant name by default is case sensit...

   PHP,Case sensitivity,Summary     2012-06-25 05:48:17