Laravel is gonna introduce two new Blade Directives as part of 5.6 release, @method and @csrf Directives. In the current Laravel 5.5 version, we are doing the following at the top of forms to create hidden inputs for the […]
Download remote URL files using Node JS, wget
In this post, I would like to show you downloading files using node js and wget. We gonna use URL, child_process and path modules to achieve this. Just go through the comments for a better understanding. You can download […]
PHP Multithreading Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?php class WebWorker extends Worker { public function __construct(SafeLog $logger) { $this->logger = $logger; } protected $logger; } /* the collectable class implements machinery for Pool::collect */ class WebWork extends Collectable { public function run() { $this->worker ->logger ->log("%s executing in Thread #%lu", __CLASS__, $this->worker->getThreadId()); $con = mysql_connect('localhost',' root',''); $res = mysql_select_db('tests',$con); mysql_query("SELECT COUNT(*) FROM `tests`.`t`",$con); mysql_query("INSERT INTO `tests`.`t` (`id`, `s`, `t`, `date`) VALUES (NULL, '1', '1', CURRENT_TIMESTAMP);",$con) ; $this->setGarbage(); } } class SafeLog extends Stackable { protected function log($message, $args = []) { $args = func_get_args(); if (($message = array_shift($args))) { echo vsprintf( "{$message}\n", $args); } } } $pool = new Pool(10, 'WebWorker', [new SafeLog()]); foreach(range(1,100000) as $k) { $pool->submit($w=new WebWork()); $pool->submit(new WebWork()); $pool->submit(new WebWork()); } $pool->shutdown(); $pool->collect(function($work){ return $work->isGarbage(); }); var_dump($pool); ?> |
ROR – How to update email of user when using devise gem?
If you update user email address when you are using device gem, it will be stored in the unconfirmed_email column and it will trigger email by asking confirmation with a confirmation link. If you want to override this […]
Laravel 5.5 – How to log all Eloquent Queries
In this post, I will show you simple method to log each and every Eloquent Query of your application executes. We gonna log queries to the storage/logs/laravel.log file. To log database queries we gonna add a database […]