Subscribe to RSS Feed

Posts Tagged ‘ PHP ’

PHP MongoDB (Mongo Database) Driver Installation on Linux, UNIX, BSD and Mac OS X

MongoDB PHP driver is very simple install on Linux, UNIX, BSD and Mac OS X. You need just PEAR (PHP Extension and Application Repository) with PECL repository. Normally PHP development (dev) package and PHP Pear package installation from package management system is enough to get PEAR working. Also go-pear.php script can be used.

» Continue Reading "Install PHP MongoDB (mongo) Driver on Linux, Mac OS X, Windows, UNIX, BSD"
2 Comments

PHP has large number of predefined constants. This HOWTO will present the seven most important, most practical and most useful PHP Magic Constants.

  • __FILE__ – The full path and filename of the file.
  • __DIR__ – The directory of the file.
  • __FUNCTION__ – The function name.
  • __CLASS__ – The class name.
  • __METHOD__ – The class method name.
  • __LINE__ – The current line number of the file.
  • __NAMESPACE__ – The name of the current namespace

This is example PHP script with comments, which demonstrate howto use all previously mentioned PHP Magic Constants.

» Continue Reading "Howto Use PHP Magic Constants: __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __LINE__, __NAMESPACE__"

Please leave a comment

I was using simple function to calculate difference between two dates and timestamps until I noticed, it’s not working correctly in long intervals. It’s very easy to calculate difference between two timestamps in seconds, but it’s much more complicated print difference in human readable format. The Internet can be found in a wide range of ways to do this thing, but as a rule they use a fixed amount of seconds for the year and the month. So if we calculate year with using 365 or 365.25 days and month using 30 or 31 then the difference is not accurate, because of leap years, DST (Daylight Saving Time) and so on.

Because of this problem, I decided to make a function (at least in the short testing) to return the right kind of differences between the UNIX timestamps and dates in human readable format. This function uses PHP strtotime function to calculate real differences and can handle leap years and DST. This function can also return Twitter like about texts with precision parameter.

» Continue Reading "PHP: Calculate Real Differences Between Two Dates or Timestamps"

1 Comment

PHP Command Line Interface (CLI) has not built-in coloring for script output, like example Perl language has (perldoc.perl.org/Term/ANSIColor.html). So I decided to make own class for coloring PHP CLI output. This class works only Bash shells. This class is easy to use. Just create new instance of class and call getColoredString function with string and foreground color and/or background color.

PHP Class for Coloring PHP Command Line (CLI) Scripts Output

» Continue Reading "PHP Class for Coloring PHP Command Line (CLI) Scripts Output – PHP Output Colorizing Using Bash Shell Colors"

1 Comment

In many cases, it is really useful to know the exact time for how long a PHP script is running or how long will take PHP web page load. On the other hand it is also useful to know that how long a particular script operation or part of page load will take.

Following PHP Timing class is very simple to use, only create class and start timing and stop timing. Elapsed time function can be used also (elapsed time is calculated from script start time). Statistics can be displayed in print-functions and the same information without any formatting can also get with get-functions.

» Continue Reading "PHP Timing Class – Class for Measure PHP Scripts Execution Time and PHP Web Page Load Time"

Please leave a comment