') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - dSpaceLabs/Queue: General Queueing library that supports various backend storage systems · GitHub
Skip to content

Repository files navigation

Queue Component Build Status

General queue library for PHP, ability to support various different queue systems.

For more documentation, see the wiki.

Installation

composer require dspacelabs/queue

Usage

<?phpuseDspacelabs\Component\Queue\Message;
// Publishing messages to a queue$message = newMessage($body);
$queue->publish($message);
/** * This will publish a message to the queue you created, the $body can be * anything you want. */// Receive messages$message = $queue->receive();
$body = $message->getBody();
// ... Process Data .../** * $message will be the message that was published. `->receive()` can be put * into a foreach loop if you want to continue to process the queue until * all the messages are processed, use a for loop in you only want to process * a small number of the messages *//** * Once you are done processing a message, it needs to be deleted from the queue */$queue->delete($message);

Messages, Queues, Broker

Messages are published to queues. When you receive a message from a queue, you will be interacting with this class.

Queues are where you publish your messages to. For example, a Queue could be an AWS SQS, RabbitMQ, or any other queue you can think of.

The Broker helps you keep track of queues. So instead of having 100 different queue objects all over, you just add all those to the Broker and let the Broker sort them out. You just get the ones you need.

Using the FileQueue

The FileQueue will store messages on disk and is good to use for local development.

Messages are stored on disk in the file naming format "name.timestamp.message" so you can have multiple file queues share the same directory.

<?phpuseDspacelabs\Component\Queue\FileQueue;
useDspacelabs\Component\Queue\Message;
$queue = newFileQueue('queue.name', '/tmp/');
$queue->publish(newMessage('Hello World!'));
// ...$message = $queue->receive();
$body = $message->getBody(); // $body === "Hello World!"$queue->delete($message);

Using the SqsQueue

Requires Amazon PHP SDK.

php composer.phar require aws/aws-sdk-php
<?phpuseAws\Credentials\Credentials;
useAws\Sqs\SqsClient;
useDspacelabs\Component\Queue\SqsQueue;
$credentials = newCredentials($accessKey, $secretKey);
$client = newSqsClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => $credentials,
]);
$queue = newSqsQueue($client, $queueUrl, $name);

Using the StandardQueue

The standard queue is mainly used for testing. Once this is setup you can quickly test your workflow. Keep in mind that this has some drawbacks mainly that the messages are not persisted.

<?php// First you need to setup the Queue$queue = new \Dspacelabs\Component\Queue\StandardQueue('queue.name');
// Create a message that will be sent to the queue$message = new \Dspacelabs\Component\Queue\Message('Hello World A');
// Publish the message$queue->publish($message);
// Consume all messages/** @var Message $msg **/while ($msg = $queue->receive()) {
// process message// ...// Delete the Message from the queu$queue->delete($msg);
}

NOTE: When using the StandardQueue, you do not need to delete the message like in this example $queue->delete($msg); HOWEVER there are some queues out there that support this.

Using the RedisQueue

To use the RedisQueue you need to install Predis

composer require predis/predis

Once you have done that, you can begin to use the Redis as one of the possible Queues.

<?phpusePredis\Client;
useDspacelabs\Component\Queue\RedisQueue;
$client = newClient();
$queue = newRedisQueue($client, 'queue.name');

See https://github.com/nrk/predis for Predis documentation.

Using the Broker

If you have multiple queues, you can use the Broker which will just help you manage the various queues you have. For example, you could be using multiple SQS queues and want a single point to access those at. The Broker will help you with this.

It's also important to point out that the broker supports all queue types in this library. So you can use the SQS Queue, Standard Queue, or a custom queue that you made.

<?phpuseDspacelabs\Component\Queue\Broker;
$broker = newBroker();
// I assume you already have a queue$broker->addQueue($queue);
// `queue.name` is the name given to the queue you created// I assume you already have a `$message` created$broker->get('queue.name')->publish($message);
$broker->get('queue.other')->publish($messageOther);

Change Log

See CHANGELOG.md.

License

Copyright (c) 2015-2017 dSpace Labs LLC

See LICENSE for full license.

About

General Queueing library that supports various backend storage systems

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages