Tips & Tricks

09
Apr
2011
admin

Managing Cron Jobs with PHP

Background – An Overview of the Crontab

Let’s face it, having the ability to schedule tasks to run in the background is just great! From backing up an SQL database, fetching / sending emails to running clean up tasks, analyzing performance, or even grabbing RSS feeds, cron jobs are fantastic!

Although the syntax of scheduling a new job may seem daunting at first glance, it’s actually relatively simple to understand once you break it down. A cron job will always have five columns each of which represent a chronological ‘operator’ followed by the full path and command to execute:

  1. * * * * * home/path/to/command/the_command.sh  

Each of the chronological columns has a specific relevance to the schedule of the task. They are as follows:

  • Minutes represents the minutes of a given hour, 0-59 respectively.
  • Hours represents the hours of a given day, 0-23 respectively.
  • Days represents the days of a given month, 1-31 respectively.
  • Months represents the months of a given year, 1-12 respectively.
  • Day of the Week represents the day of the week, Sunday through Saturday, numerically, as 0-6 respectively.
  1. Minutes [0-59]  
  2. |   Hours [0-23]  
  3. |   |   Days [1-31]  
  4. |   |   |   Months [1-12]  
  5. |   |   |   |   Days of the Week [Numeric, 0-6]  
  6. |   |   |   |   |  
  7. *   *   *   *   * home/path/to/command/the_command.sh  

So, for example, if one wanted to schedule a task for 12am on the first day of every month it would look something like this:

  1. 0 0 1 * * home/path/to/command/the_command.sh  

If we wanted to schedule a task to run every Saturday at 8:30am we’d write it as follows:

  1. 30 8 * * 6 home/path/to/command/the_command.sh  
28
Mar
2011
admin

How to search text in files or folders in Command Line of Ubuntu

 

Applications -> Accessories -> Terminal

and write the following command:

grep -i -n -r ‘searchtext’ *

-i for ignore case sens, -n for line number and -r for recursive

where searchtext is the text you want to search in your files.

This will bring the results with the file names, containing all the files which has the text searchtext.

12
Mar
2010
admin

How do I fix “Setup did not find any hard disk drives installed in your computer” error during Win XP Pro install?

When I try to reinstall Windows XP in ASUS Z99Eseries, I got following message:
"Setup did not find any hard disk drives installed in your computer.

Make sure any hard disk dirves are powered on and properly connected to your computer, and that any disk-related hardware configuration is correct. This may involve running a manufacturer-supplied to diagnostic or setup program.

Setup cannot continue. To quit Setup, press F3."

So, I try to fix this more and more time. And finally fixed this following way:

17
Aug
2009
admin

Disable PHP's Bad Features

Register Globals (register_globals):
Whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables.
We cannot disable register_globals from the script side (using ini_set, like we normally might), but we can use an .htaccess files to do this. Some hosts also allow you to have a php.ini file on the server.

Disabling with .htaccess
php_flag register_globals 0

Disabling with php.ini
register_globals = Off
 

05
Aug
2009
admin

Develope Bangla Unicode based Web Application using PHP-MySQL

1 .Make the database and Tables with CHARACTER utf8 and collation_connection =’utf8_general_ci’
2 . Must add following two lines just after selecting the database, i.e mysql_select_db() function:
mysql_query(’SET CHARACTER SET utf8′);
mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);
4 . Set the META-TAG as “Content-Type: text/html; charset=UTF-8″

25
Jan
2009
admin

Learn PHP from Scratch

PHP stands for Hypertext Preprocessor. While other languages, like Javascript, function on the client-side, your PHP code will execute on the server level. It works seamlessly with our HTML. Furthermore, your PHP can be embedded within your HTML and vice versa. The important thing to remember is that, no matter how complicated your PHP is, it will ultimately be output as simple HTML.

07
Jan
2009
admin

Customize a PHP configuration file at Runtime

You can change your php.ini file configuration at runtime using PHP scripts. Customize such settings as whether global variables are turned on, the default directory to upload files to when writing upload scripts, and the maximum allowed size for uploaded files.

PHP Options and Information functions enable you to get a lot of information about PHP itself, e.g. runtime configuration, loaded extensions, version and much more. You'll also find functions to set options for your running PHP.

01
Nov
2008
admin

Regular expression in PHP

Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are basically pattern matching inside of text. Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax.

27
Oct
2008
admin

PHP Optimization Tips

1. If a method can be static, declare it static. Speed improvement.

2. str_replace is faster than preg_replace, but strtr is faster than str_replace .

3. $row['id'] is 7 times faster than $row[id] , because if you don't supply quotes it has to guess which index you meant, assuming you didn't mean a constant.

4. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

5. echo is faster than print

25
Sep
2008
admin

Most Important Date and Time function of PHP

Following Date & Time Function so helpfull:

1. Number of days in a month
The function 'cal_days_in_month' is used to return the number of days in a month. This function takes three arguments one for calendar name, month value and year value respectively.

Syntax:
cal_days_in_month( CAL_GREGORIAN, $intMonth, $intYear);
Example:
cal_days_in_month ( CAL_GREGORIAN, 1, 2005); Output: 31

2. Calculating Days In A Month

Pages

Subscribe to RSS - Tips &amp; Tricks