Category : "Tutorial"

Php web development tutorials

PHP manage multiple cronjobs with a single crontab entry

In many php applications there are multiple tasks that need to be run via cron at different times. In a typical application you may be doing the following tasks via cronjobs : 1. Backup database. 2. Send out email to subscribers. 3. Clear temporary files. 4. Fetch xml feeds from some source and store them in database. So if you had separate php files doing ...

PHP check if a timestamp matches a given cron schedule

desktop:~$ php -a Interactive shell php > echo time(); 1319362432 php > Above is an example of a given timestamp. And a cron schedule can look like this 0 5 * * * - which means run everyday at 5 hours and 0 minutes. Now in a php application you may need to test if a given timestamp , say 1319362432 matches a given cron schedule ...

Check if php is running from cli (command line)

Php from command line PHP scripts are usually opened in a web browser. But they can be run from command line or terminal as well. The syntax to run a script from commandline is very much similar to python or perl. php /path/to/script/index.php Inside a script it might be necessary to test if it is being run from command line or not. For ...

Resize large images in php with imagemagick

Resizing images Web applications often need to work with images like pictures of users or photos etc. So the need to need to resize images comes up when creating thumbnails for example or compressing images for storage. The default library to handle image operations in php is GD. It can be used to resize images. Resize with GD The function imagecopyresampled is used ...

Check system load in php on linux

System load System load is a measure of how busy the system is running the processes. Higher system load simply means more processes are running and more are waiting to be run. When coding php applications, it sometimes is useful or necessary to find the current load on the server/system. For example if you want to run a long resource intensive ...

PHP: Get visitor’s location, city, country from IP address

Ip to Location Many applications need to get information about the geographical location of the user/visitor on their websites. This can be done in many ways. There are online services like ipinfodb and geoio that provide web based api to get the geolocation information about a given ip address. Services like Maxmind geoip provide free database that can be installed on ...

Parse and change date format in php

Parsing dates Most php applications need to parse dates and convert them to timestamps for example. Parsing is also necessary to convert the date into a more standard format like yyyy-mm-dd which can be stored in a database like mysql. Mysql database stores dates in the format yyyy-mm-dd like 2009-04-15. However humans are more used to the formats like dd-mm-yyyy or mm-dd-yyyy ...

PHP Database Class to access Mysql

This is a simple class that evolved out of the php code I wrote so far. It has the following functions : 1. dbms() - The constructor to do the initialisation like connecting to the database etc. 2. query($query) - The method to take a sql string and perform the query. 3. close() - Close the database connection 4. backup() - Create a backup of ...

Restore Mysql Database from a sql or zip file using PHP

In a previous post we learnt how to inside php. In this example the same zip file would be used to restore the database. Code // Function to restore from a file function restore($path) { $f = fopen('restore/temp.sql' , 'w+'); if(!$f) { echo "Error While Restoring Database"; return; } $zip = new ZipArchive(); ...

Backup mysql database with php and zip it

Many php applications prefer to backup the mysql database from within the application and save it as an archive. The mysqldump commandline utility can be used to perform this function of backing up a mysql database as sql file. The command would be like this : mysqldump --user=$username --password=$password --opt $db_name > $dir/backup.sql The above command shall dump the database named $db_name ...

Pages:«123456»


Connect with us