Wednesday, 14 May 2014

PHP Upload File In Amazon S3 Bucket - Code Snippets

PHP Upload File In Amazon S3 Bucket - Code Snippets

Get List of buckets in Amazon S3 bucket and upload a file in Amazon S3 bucket with Zend Framework.

Uploading files in zend framework is very simple because zend framework provides the API which is very simple to use.

Please use following code to upload photos in zend framework.
$my_aws_key = 'AWS_KEY';
$my_aws_secret_key = 'AWS_SECRET_KEY';
$s3 = new Zend_Service_Amazon_S3($my_aws_key, $my_aws_secret_key);

/** Get List of buckets * */
$list = $s3->getBuckets();
foreach ($list as $bucket) {
    echo "Bucket: $bucket\n";
}
/** Get List of buckets * */


/** get Bucket Files **/
$files = $s3->getObjectsByBucket("BUCKET_NAME");
foreach ($files as $file) {
    echo "File: $file\n";
}
/** get Bucket Files **/


$imageName = 'http://static.zend.com/img/yellowpages/ZFCE-logo-XS.jpg';
try {
    $s3->putFile($imageName, "BUCKET_NAME/ZFCE-logo-XS.jpg", array(
        Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
        'x-amz-storage-class' => 'REDUCED_REDUNDANCY'
            )
    );
die('uploaded successfully');
} catch (Exception $e) {
    pr($e->getMessage());
    die;
}

Monday, 12 May 2014

Crontab Interview Questions and Answers


Crontab Interview Questions and Answers

A cron job is a Linux command for scheduling script on your server to complete repetitive tasks automatically. Scripts executed as a cron job are typically used to modify files, databases and manage caching.

Cron is controlled by "crontabs". There is the master file in /etc/crontab. Each user's cronjob is stored in /var/spool/cron/username directory.


Benefits of Cron
  • Cron already built, and works, very reliable
  • You more easily have control over when it runs. You control the minute, hour, day, month and weekday  etc.
  • You can run many cron with difference of 15 seconds
  • You can manage cronjob from admin panel
  • Need not run manually, Schedule once will execute manually.




Install crontab
crontab -a filename

Edit the crontab
$ crontab -e

Display crontab
crontab -l

Display the last edit the crontab file
crontab -v

Remove crontab
crontab -r

Following are the syntax for cron
minute(s) hour(s) day(s) month(s) weekday(s) command(s) "Argument1" "Argument2"
1 * 3 4 5 /path/to/command arg1 arg2

If you don't have parameter put star(*)


Description of Cron fields





Field       Description
minute(0-59) The exact minute that the command sequence executes
hour (0-23) The hour of the day that the command sequence executes
day(1-31)   The day of the month that the command sequence executes
month(1-12) The month of the year that the command sequence executes
weekday(0-6)         The day of the week that the command sequence executes (Sunday = 0, Monday = 1, Tuesday = 2, and so forth)
command(s) File Path    Absolute path CronFile
Argument               Argument (IF you want to pass an argument)