Skip to main content

Posts

Showing posts from February, 2018

Laravel working with Queues

What are queues in web development? Queues allow you to defer/postpone the processing of a time consuming task, such as sending an e-mail, until a later time, thus drastically speeding up the web requests to your application, which returns a response and serves the client significantly faster than it would be if the task ran synchronously. The Laravel Queue component provides a unified API across a variety of different queue services. There are different queue services. Some of them are hosted elsewhere, but some of them can be self-hosted, such as Beanstalkd, which I'll cover here. How do they work behind the scenes? Once you push a job onto the queue (from somewhere within your code, e.g. send an email after user has registered), all that the client has to wait for is for job to be pushed onto the queue service that is listening for jobs, and doesn't have to wait for the queue service to finish the job itself. The most trivial example would be a McDonalds employee ...

Laravel 5 - Autocomplete Mutiple Fields Using jQuery, Ajax and MySQL

In this example, I am going to search country using autocomplete functionality and while selecting country name from search list, the other fields will populate corresponding to search type. Step 1: Create Sample Table   In first step, I will create sample table "countries" to test this code. CREATE TABLE `countries` ( `id` int(11) NOT NULL AUTO_INCREMENT, `sortname` varchar(3) NOT NULL, `name` varchar(150) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=247 DEFAULT CHARSET=utf8   Step 2: Add routes In this step, I will add following two routes : routes/web.php Route :: get ( 'autocomplete' , 'AjaxAutocompleteController@index' ); Route :: get ( 'searchajax' , [ 'as' => 'searchajax' , 'uses' => 'AjaxAutocompleteController@searchResponse' ]); Using first route, We will display a form to user to search country and get the response from second routes. Step 3: Create Co...

Async Queues In Laravel

Push a function/closure to the background. For Laravel 5.4, check the 0.6 branch For Laravel 5.3, check the 0.5 branch Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. The only difference is that the closure is sent to the background without waiting for the response. This package is more usable as an alternative for running incidental tasks in the background, without setting up a 'real' queue driver. Note: This is using the DatabaseQueue, so make sure you set that up first, including migrations. Install Require the latest version of this package with Composer composer require barryvdh/laravel-async-queue Add the Service Provider to the providers array in config/app.php Barryvdh\Queue\AsyncServiceProvider::class, You need to create the migration table for queues and run it. $ php artisan queue:table $ php artisan migrate You should now be able to use the async driver in config/queue.php. Use the same config a...