Categories
Bangla PHP Screencast

বাংলা স্ক্রীনকাস্ট – S.O.L.I.D ডিজাইন প্রিন্সিপলস

The Video is available in HD

বিদ্র: হঠাৎ লোড শেডিং এর কারনে 00:29 এর কাছাকাছি থেকে 5:20 এর কাছাকাছি পর্যন্ত সময়ে সাউন্ড কোয়ালিটি খারাপ হওয়ার পাশাপাশি একটি বিরক্তিকর নয়েজ তৈরি হয়েছে । এই সমস্যার জন্য আমি আন্তরিক ভাবে দু:খিত

Categories
PHP

Using Laravel Queues Standalone (Outside Laravel)

The title is pretty self explanatory. We know how to use Queues inside Laravel. But Laravel components are also usable outside Laravel itself. Today we’re going to see how to implement our own workers on top of the “Illuminate\Queue” package.

Installing the required components:

What do we need?

In our example, we shall be using “Beanstalk” for message queueing. So please make sure you have it installed. This is how to install it on OS X using homebrew:

Then we need to install these following PHP packages. We can use Composer to install them from the Packagist repository.

  • “illuminate/queue” – the queue component
  • “pda/pheanstalk” – we shall use the beanstalk driver, so we need the beanstalk client
  • “illuminate/encryption” – some drivers need the encryption class

So this how our composer.json looks like:

Now we need to make sure that all the required packages are installed.

Let’s write the codes:

We first create a file named “loader.php” which will contain the common part. In this file, we shall construct a Queue object and add connection to Beanstalk. Here’s the code:

Let’s say we shall have some emailing tasks which would send email to our users. Let’s create a new file named “handlers.php” and create a class named “SendEmail”. This class must have a “fire()” method which can take the Job instance and data as arguments. Here’s sample codes:

OK, we just created our awesome email sending class. Our task handler is ready. Now we need to create workers which would keep running and handle tasks from the queue. We create a sample worker named “worker.php”:

We have handlers written and workers ready for some action. Let’s launch the worker:

The workers would fire up and keep listening to the queue. Whenever a new task would arrive, it would take it off the queue and process it. So now we need to queue some tasks. Let’s do that now:

Now if you look at the terminal window where you ran the worker, you would notice the output from the job handlers.

Categories
Bangla Javascript NodeJS Screencast

নোডস্কুল – লার্নইউনোড – পর্ব ২