Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function createQueue($queueName, array $queueOptions = array())
 {
     $attributes = array();
     foreach ($queueOptions as $name => $value) {
         $attributes[] = array('Name' => $name, 'Value' => $value);
     }
     // Enable Long Polling by default
     if (!isset($attributes['ReceiveMessageWaitTimeSeconds'])) {
         $attributes[] = array('Name' => 'ReceiveMessageWaitTimeSeconds', 'Value' => 20);
     }
     $response = $this->parseResponse($this->sqs->create_queue($queueName, array('Attribute' => $attributes)));
     return new Queue($this->extractQueueNameFromUrl((string) $response->CreateQueueResult->QueueUrl), $this);
 }
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Make sure that at least one argument was given
if ($argc < 2) {
    exit('Usage: ' . $argv[0] . " URL...\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
// Get the Queue URL
$queueURL = $sqs->create_queue(URL_QUEUE)->body->CreateQueueResult->QueueUrl;
// Load each URL
for ($i = 1; $i < $argc; $i++) {
    // Create message
    $histItem = array('Posted by ' . $argv[0] . ' at ' . date('c'));
    $message = json_encode(array('Action' => 'FetchPage', 'Origin' => $argv[0], 'Data' => $argv[$i], 'History' => $histItem));
    // Post message
    $res = $sqs->send_message($queueURL, $message);
    if ($res->isOK()) {
        print "Posted '{$message}' to queue " . URL_QUEUE . "\n";
    } else {
        $error = $res->body->Error->Message;
        print "Could not post message to queue: {$error}\n";
    }
}
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Define image layout constants
define('BORDER_LEFT', 12);
define('BORDER_RIGHT', 12);
define('BORDER_TOP', 12);
define('BORDER_BOTTOM', 12);
define('IMAGES_ACROSS', 4);
define('IMAGES_DOWN', 4);
define('GAP_SIZE', 6);
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Get the queue URL
$queueURL_Render = $sqs->create_queue(RENDER_QUEUE)->body->CreateQueueResult->QueueUrl;
// Pull, process
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $queueURL_Render);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
        $imageKeys = $messageDetail['Data'];
        $pageTitle = $messageDetail['PageTitle'];
        print "Processing message with " . count($imageKeys) . " images:\n";
        // Create destination image
        $outX = BORDER_LEFT + BORDER_RIGHT + IMAGES_ACROSS * THUMB_SIZE + (IMAGES_ACROSS - 1) * GAP_SIZE;
        $outY = BORDER_TOP + BORDER_BOTTOM + IMAGES_DOWN * THUMB_SIZE + (IMAGES_DOWN - 1) * GAP_SIZE;
        $imageOut = ImageCreateTrueColor($outX, $outY);
Exemplo n.º 4
0
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/book.inc.php';
// Make sure that at least one argument was given
if ($argc < 2) {
    exit('Usage: ' . $argv[0] . " URL...\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
$res = $sqs->create_queue(URL_QUEUE);
if ($res->isOK()) {
    $queueURL = urlFromQueueObject($res);
}
// Load each URL
for ($i = 1; $i < $argc; $i++) {
    // Create message
    $histItem = array('Posted by ' . $argv[0] . ' at ' . date('c'));
    $message = json_encode(array('Action' => 'FetchPage', 'Origin' => $argv[0], 'Data' => $argv[$i], 'History' => $histItem));
    // Post message
    $res = $sqs->send_message($queueURL, $message);
    if ($res->isOK()) {
        print "Posted '{$message}' to queue " . URL_QUEUE . "\n";
    } else {
        $error = $res->body->Error->Message;
        print "Could not post message to queue: {$error}\n";
Exemplo n.º 5
0
<?php

require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php';
define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ');
define('AWS_SECRET_KEY', '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');
define('AWS_ACCOUNT_ID', '457964863276');
$queue_name = $_GET['queue'];
$sqs = new AmazonSQS();
$sqs->set_region($sqs::REGION_EU_W1);
$queue = $sqs->create_queue($queue_name);
$queue->isOK() or die('could not create queue ' + $queue_name);
$receive_response = $sqs->receive_message($queue->body->QueueUrl(0));
$delete_response = $sqs->delete_message($queue->body->QueueUrl(0), (string) $receive_response->body->ReceiptHandle(0));
$body = json_decode($receive_response->body->Body(0));
pr($body);
function pr($var)
{
    print '<pre>';
    print_r($var);
    print '</pre>';
}
Exemplo n.º 6
0
 *
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
// Make sure that at least one argument was supplied
if (count($argv) < 2) {
    exit("Usage: " . $argv[0] . " QUEUE...\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
// Process each argument
for ($i = 1; $i < count($argv); $i++) {
    $queue = $argv[$i];
    $res = $sqs->create_queue($queue);
    if ($res->isOK()) {
        print "Created queue '{$queue}'\n";
    } else {
        $error = (string) $res->body->Error->Message;
        print "Could not create queue '{$queue}': {$error}.\n";
    }
}
exit(0);
Exemplo n.º 7
0
    exit("Usage: " . $argv[0] . " bucket name\n");
}
$bucket = $argv[1] == '-' ? BOOK_BUCKET : $argv[1];
// Define image layout constants
define('BORDER_LEFT', 12);
define('BORDER_RIGHT', 12);
define('BORDER_TOP', 12);
define('BORDER_BOTTOM', 12);
define('IMAGES_ACROSS', 4);
define('IMAGES_DOWN', 4);
define('GAP_SIZE', 6);
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Convert the queuenames to URLs
$res = $sqs->create_queue(RENDER_QUEUE);
if ($res->isOK()) {
    $renderQueueURL = urlFromQueueObject($res);
}
// Pull, process
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $renderQueueURL);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
        $imageKeys = $messageDetail['Data'];
        $pageTitle = $messageDetail['PageTitle'];
        print "Processing message with " . count($imageKeys) . " images:\n";
        // Create destination image
Exemplo n.º 8
0
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
// Make sure that an argument was supplied
if ($argc != 2) {
    exit("Usage: " . $argv[0] . " QUEUE_NAME\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
$queueName = $argv[1];
// Get URL for queue
$queueURL = $sqs->create_queue($queueName)->body->CreateQueueResult->QueueUrl;
// Poll for new items
while (true) {
    $res = $sqs->receive_message($queueURL);
    if ($res->isOK()) {
        if (isset($res->body->ReceiveMessageResult->Message)) {
            $message = $res->body->ReceiveMessageResult->Message;
            $messageBody = $message->Body;
            $receiptHandle = (string) $message->ReceiptHandle;
            print "Message: '{$messageBody}'\n";
            $sqs->delete_message($queueURL, $receiptHandle);
        } else {
            sleep(1);
        }
    } else {
        $error = $res->body->Error->Message;
Exemplo n.º 9
0
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/simple_html_dom.php';
require_once 'include/book.inc.php';
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Get the Queue URLs
$queueURL_Parse = $sqs->create_queue(PARSE_QUEUE)->body->CreateQueueResult->QueueUrl;
$queueURL_Image = $sqs->create_queue(IMAGE_QUEUE)->body->CreateQueueResult->QueueUrl;
// Pull, process, post
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $queueURL_Parse);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
        $pageURL = $messageDetail['Data'];
        // Fetch and parse the page
        print "Processing URL '{$pageURL}':\n";
        $dom = new simple_html_dom();
        $dom->load_file($pageURL);
        // Get the page title
Exemplo n.º 10
0
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Get the Queue URLs
$queueURL_URL = $sqs->create_queue(URL_QUEUE)->body->CreateQueueResult->QueueUrl;
$queueURL_Parse = $sqs->create_queue(PARSE_QUEUE)->body->CreateQueueResult->QueueUrl;
// Pull, process, post
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $queueURL_URL);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
        $pageURL = $messageDetail['Data'];
        // Fetch the page
        print "Processing URL '{$pageURL}':\n";
        $html = file_get_contents($pageURL);
        print "  Retrieved " . strlen($html) . " bytes of HTML\n";
        // Store the page in S3
Exemplo n.º 11
0
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/book.inc.php';
if ($argc != 2) {
    exit("Usage: " . $argv[0] . " bucket name\n");
}
$bucket = $argv[1] == '-' ? BOOK_BUCKET : $argv[1];
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Convert the queuenames to URLs
$res = $sqs->create_queue(URL_QUEUE);
if ($res->isOK()) {
    $urlQueueURL = urlFromQueueObject($res);
}
$res = $sqs->create_queue(PARSE_QUEUE);
if ($res->isOK()) {
    $parseQueueURL = urlFromQueueObject($res);
}
// Pull, process, post
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $urlQueueURL);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
Exemplo n.º 12
0
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/book.inc.php';
// Create the feed queue, if necessary, and grab its URL
$sqs = new AmazonSQS();
$res = $sqs->create_queue(FEED_QUEUE);
if ($res->isOK()) {
    $feedQueueUrl = urlFromQueueObject($res);
}
// Make sure that at least one argument was given
if ($argc < 2) {
    exit('Usage: ' . $argv[0] . " [URL] [-f FILE] ...\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
// Process each argument
for ($i = 1; $i < $argc; $i++) {
    if ($argv[$i] == '-f') {
        $urls = file($argv[++$i]);
        foreach ($urls as $url) {
            loadURL($sqs, $feedQueueUrl, trim($url));
Exemplo n.º 13
0
<?php

require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php';
define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ');
define('AWS_SECRET_KEY', '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');
define('AWS_ACCOUNT_ID', '457964863276');
# set priority
$priority = $_GET['priority'];
# construct the message
$job_description = array('template' => 'https://s3-eu-west-1.amazonaws.com/production/templates/223/template_1.xml', 'assets' => 'https://s3-eu-west-1.amazonaws.com/production/assets/223', 'result' => 'https://s3-eu-west-1.amazonaws.com/production/pdfs/223');
$body = json_encode($job_description);
$sqs = new AmazonSQS();
$sqs->set_region($sqs::REGION_EU_W1);
if ('high' === $priority) {
    $high_priority_jobs_queue = $sqs->create_queue('high-priority-jobs');
    $high_priority_jobs_queue->isOK() or die('could not create queue high-priority-jobs');
    $response = $sqs->send_message($high_priority_jobs_queue->body->QueueUrl(0), $body);
} else {
    $normal_priority_jobs_queue = $sqs->create_queue('normal-priority-jobs');
    $normal_priority_jobs_queue->isOK() or die('could not create queue normal-priority-jobs');
    $response = $sqs->send_message($normal_priority_jobs_queue->body->QueueUrl(0), $body);
}
pr($response->body);
function pr($var)
{
    print '<pre>';
    print_r($var);
    print '</pre>';
}
Exemplo n.º 14
0
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
require_once 'include/simple_html_dom.php';
require_once 'include/book.inc.php';
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Convert the queuenames to URLs
$res = $sqs->create_queue(PARSE_QUEUE);
if ($res->isOK()) {
    $parseQueueURL = urlFromQueueObject($res);
}
$res = $sqs->create_queue(IMAGE_QUEUE);
if ($res->isOK()) {
    $imageQueueURL = urlFromQueueObject($res);
}
// Pull, process, post
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $parseQueueURL);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
 /**
  * Method: create_queue()
  * 	Identical to <AmazonSQS::create_queue()>. The queue URL created from this method will replace the queue URL already being used with this class.
  * 
  * 	New queue URL will NOT automatically apply when using MultiCurl for parallel requests.
  * 
  * Access:
  * 	public
  * 
  * Parameters:
  * 	queue_name - See <AmazonSQS::create_queue()>.
  * 	returnCurlHandle - See <AmazonSQS::create_queue()>.
  * 
  * Returns:
  * 	<TarzanHTTPResponse> object
  * 
  * See Also:
  * 	Example Usage - http://tarzan-aws.com/docs/examples/sqsqueue/create_queue.phps
  */
 public function create_queue($queue_name, $returnCurlHandle = null)
 {
     $data = parent::create_queue($queue_name, $returnCurlHandle);
     if ($data instanceof TarzanHTTPResponse) {
         $this->queue_url = (string) $data->body->CreateQueueResult->QueueUrl;
     }
     return $data;
 }