I'm not sure, but maybe it will be useful for you?:
http://net.tutsplus.com/tutorials/php/how-to-use-amazon-s3-php-to-dynamically-store-and-manage-files-with-ease/php-script to clean old files to Amazon S3:
<?php
/**
* @example "s3cmd ls s3://bucket/path/to/dir/ | php this_file.php"
*/
define( 'NUM_DAYS', 10 );
$stdin = file( 'php://stdin', FILE_IGNORE_NEW_LINES );
$files = array();
for ( $i=0, $len=count( $stdin ); $i<$len; $i++ ) {
# пропускаем первую строку, поскольку в ней содержится текущая директория
if ( $i == 0 ) {
continue;
}
# 1 - дата последнего изменения
# 2 - размер в байтах
# 3 - адрес в букете
preg_match( '#([\d]{4}-[\d]{2}-[\d]{2}\s[\d]{2}:[\d]{2})[\s]+([\d]+)[\s]+(s3://.*)#', $stdin[ $i ], $matches );
$matches[1] = strtotime( $matches[1] );
$files[] = $matches;
}
$bestBefore = time() - NUM_DAYS*86400;
foreach ( $files as $file ) {
if ( $file[1] < $bestBefore ) {
$command = 's3cmd del ' . str_replace( ' ', '+', $file[3] );
`$command`;
}
}