Charrua

Owner at Charrua

Hire Me

Experience

3,320

0 Best Reply Awards

  • Member Since 11 Months Ago
  • 14 Lessons Completed
  • 0 Favorites

13th October, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 days ago

@hondnl this is the Plesk engineer answer:

This is a known issue with plesk-php7x which have libsodium package included for stronger cryptography.

Forced initialization of crypto library on startup each PHP script depletes entropy (/dev/random) and next processes wait for another portion of randomness. So any php script can cause entropy depletion.

The developers have submitted this issue as a bug PPPM-9444 which is planned to be fixed in one of the future Plesk updates.

Please subscribe to the following article to be notified when the bug is fixed: https://support.plesk.com/hc/en-us/articles/360010129094

11th October, 2018

Charrua started a new conversation Integrating Facebook Page_insights With Laravel • 4 days ago

Hello, what would be a good workflow to integrate facebook page insights in a Laravel dashboard app?

I don't know where to start.

Any ideas would be great!

Charrua left a reply on Scheduler Running Strange • 4 days ago

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

Enable EPEL repository: yum install epel-release

Install daemon with the following command and enable it: yum install haveged

chkconfig haveged on

systemctl start haveged

10th October, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 5 days ago

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

  1. Enable EPEL repository:

    yum install epel-release

  2. Install daemon with the following command and enable it:

    chkconfig haveged on
    systemctl start haveged```
    

3rd October, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

@D9705996 Really strange news. I have talked with plesk support, an engineer logged in and he returns to me that "he cant reproduce the issue.

So I logged in and now even I can't reproduce the issue, apparently all is running on time. I have asked him if he changed anything but I'm still waiting for an answer. All crons are fired on time and tasks on time.

I have checked all logs and there is no accumulation or delay for tasks. Really strange but good (for now). Yesterday and all past days the server failed one time in 10 minutes average. Now it is running for about 5 hours without any issue.

2nd October, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

the PHP5.4 is installed by OS vendor

5.4.16 by OS vendor FPM application

This is listed in plesk. Maybe I need to update the digital oceans php version to 7.1 instead of plesk...

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

@click Yes, Laravel needs PHP >= 7.0, so I can't run it only with php (I have tried to run scheduler but it shows an error)

php /var/www/vhosts/domain***/laravel/artisan schedule:run
PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /var/www/vhosts/winnersmartialarts.com/laravel/artisan on line 33

I'm talking with the plesk support team so I let them finish their investigations and try to remove PHP 5.4 and make 7.1 the default and see what happens. Hope this solves the issue...

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

@click I think you have discovered some light...

If I run php -v the output is

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.0.3, Copyright (c) 2002-2017, by ionCube Ltd.

So for my app I needed to use 7.1 so I searched and use /opt/plesk/php/7.1/bin/php so for example my cron's php path is /opt/plesk/php/7.1/bin/php /path/to/file.php and not php /path/to/file.php

Observation: 2 different versions here....

The light comes in when running watch -n1 php test.php or watch -n1 /opt/plesk/php/7.1/bin/php test.php

If I run the one with the php 7.1 path it hangs as cron do, but the other one does not hang...

While the system is lagged, seems that using php instead of /opt/plesk/php/7.1/bin/php keeps running. Hope this helps you to send some light to the solution

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

@click, yes that's what I'm thinking, something related with php/apache/nginx as you said. The app runs smooth via browser, even when the php scripts that came from cron are delayed, the app runs as usual...

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

@shez1983 in the logs there is nothing related to what is happening. But I discovered something, someone else told me to create a bash script and test it with cron:

Bash script:

#!/bin/bash
echo $(date);
exit 0

Crontab:

* * * * * /var/www/vhosts/domain***/test.sh >> /var/www/vhosts/winnersmartialarts.com/logs/domain***/date.log

But the results surprised me, they are great:

Tue Oct 2 05:08:01 EDT 2018
Tue Oct 2 05:09:01 EDT 2018
Tue Oct 2 05:10:01 EDT 2018
Tue Oct 2 05:11:01 EDT 2018
Tue Oct 2 05:12:01 EDT 2018
Tue Oct 2 05:13:01 EDT 2018
Tue Oct 2 05:14:01 EDT 2018
Tue Oct 2 05:15:01 EDT 2018
Tue Oct 2 05:16:01 EDT 2018
Tue Oct 2 05:17:01 EDT 2018
Tue Oct 2 05:18:01 EDT 2018
Tue Oct 2 05:19:02 EDT 2018
Tue Oct 2 05:20:01 EDT 2018
Tue Oct 2 05:21:01 EDT 2018
Tue Oct 2 05:22:01 EDT 2018
Tue Oct 2 05:23:01 EDT 2018
Tue Oct 2 05:24:01 EDT 2018
Tue Oct 2 05:25:01 EDT 2018
Tue Oct 2 05:26:01 EDT 2018
Tue Oct 2 05:27:01 EDT 2018
Tue Oct 2 05:28:01 EDT 2018
Tue Oct 2 05:29:01 EDT 2018
Tue Oct 2 05:30:01 EDT 2018
Tue Oct 2 05:31:01 EDT 2018
Tue Oct 2 05:32:01 EDT 2018
Tue Oct 2 05:33:01 EDT 2018
Tue Oct 2 05:34:01 EDT 2018
Tue Oct 2 05:35:01 EDT 2018
Tue Oct 2 05:36:02 EDT 2018
Tue Oct 2 05:37:01 EDT 2018
Tue Oct 2 05:38:01 EDT 2018

So what do you think? this could be an Apache or PHP issue?

1st October, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 1 week ago

I can disable nginx if you have an idea of what can be causing this.

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@snapey I use apache with nginx, this is by default what comes with plesk, but I can disable nginx... you can see here: https://docs.plesk.com/en-US/onyx/administrator-guide/web-servers/apache-and-nginx-web-servers-linux/apache-with-nginx.70837/

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@click thank you, I will post there too.

Charrua left a reply on Scheduler Only Running Some Tasks • 2 weeks ago

Hi @D9705996 I tried to remove >> /dev/null 2>&1 from the cron job but no errors are in the output. The /var/log/cron does not show any errors, only cron executions.

There is only one schedule:run for all users. Checked.

At this time, I thinking is not a Laravel issue and more of a server issue, I have disabled the scheduler cron and enable a simple plain php cron to log when this is executed, and the same results are shown.

Cron log:

Oct 1 10:01:01 localhost CROND[2315] 
Oct 1 10:02:01 localhost CROND[2388] 
Oct 1 10:03:01 localhost CROND[2440] 
Oct 1 10:04:01 localhost CROND[2493] 
Oct 1 10:05:01 localhost CROND[2566] 
Oct 1 10:06:01 localhost CROND[2627] 
Oct 1 10:07:01 localhost CROND[2743] 

Task log:

Monday, 01-Oct-2018 10:00:01 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:06:01 EDT 
Monday, 01-Oct-2018 10:07:01 EDT 

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@click my understanding of Linux stops here too, I have tried to restart the server but the same happens. This issue is driving me crazy. Thank you for your help.

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@click I have disabled the laravel cron and setup another cron to log as you said timestamps, the same happens

Monday, 01-Oct-2018 10:00:01 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:06:01 EDT
Monday, 01-Oct-2018 10:07:01 EDT

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@click is not always at the same time:

2018-10-01 13:16:01 app.php
[2018-10-01 09:16:01] production.INFO: schedule call  
2018-10-01 13:17:01 app.php
[2018-10-01 09:17:01] production.INFO: schedule call  
2018-10-01 13:18:01 app.php
[2018-10-01 09:18:01] production.INFO: schedule call  
2018-10-01 13:19:01 app.php
[2018-10-01 09:19:02] production.INFO: schedule call  
2018-10-01 13:20:01 app.php
[2018-10-01 09:20:01] production.INFO: schedule call  
2018-10-01 13:23:22 app.php
2018-10-01 13:23:22 app.php
2018-10-01 13:23:22 app.php
[2018-10-01 09:23:22] production.INFO: schedule call  
[2018-10-01 09:23:22] production.INFO: schedule call  
[2018-10-01 09:23:22] production.INFO: schedule call  
2018-10-01 13:24:01 app.php
[2018-10-01 09:24:01] production.INFO: schedule call  
2018-10-01 13:25:01 app.php
[2018-10-01 09:25:01] production.INFO: schedule call  
2018-10-01 13:26:01 app.php
[2018-10-01 09:26:01] production.INFO: schedule call 

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@shez1983 When I say system is locked, I mean that if I run an any artisan command at 16:34:34, it will be queued and run at 16:37:53 (see the scheduler log I posted before). The server does not show any high load or any errors that I can relate to the times that this happens.

@Snapey web server is a Digital Ocean Droplet (if this is your question)

I don't even know if this is a php or more of a server issue... Because cron are executed on time but the artisan commands are like queued. Or maybe cron are queued too..

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

CentOS 7.4 x64, 1vcpu, 2gbRAM, using Plesk and PHP-FPM 7.1

I think this is more of a server miss-config than a Laravel issue at this moment.

30th September, 2018

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

@shez1983 I have tested with another cron job, independent of laravel. And the cron is also delayed when the system is "locked", it seems more of a server failure or php failure than a Laravel issue. The strange is that I can't find any errors related.

Charrua left a reply on Scheduler Running With Delay (not On Time) • 2 weeks ago

Hi @Snapey I have fresh results:

I have discovered that if I execute any artisan command during the "hang up" it takes forever. Lets say you run any artisan command at 16:24 this command is not resolved until 16:27:31 (when the system is "locked out")

I have no more ideas... Have looked in logs and all that but NO CLUE. I think is not Laravel, maybe is a server issue. Server load is really little, is a droplet for a private app with 15 users. Mysql queries are not slow (I have activate the slow query log)

Cron log:

Sep 30 16:20:01 localhost CROND[28616]
Sep 30 16:21:01 localhost CROND[854]
Sep 30 16:22:02 localhost CROND[988]
Sep 30 16:23:01 localhost CROND[1062]
Sep 30 16:24:01 localhost CROND[1132]
Sep 30 16:25:01 localhost CROND[1199]
Sep 30 16:26:01 localhost CROND[1255]
Sep 30 16:27:01 localhost CROND[1315]
Sep 30 16:28:01 localhost CROND[1411]
Sep 30 16:29:01 localhost CROND[1508]
Sep 30 16:30:01 localhost CROND[1599]
Sep 30 16:31:01 localhost CROND[1670]
Sep 30 16:32:01 localhost CROND[1742]
Sep 30 16:33:01 localhost CROND[1807]
Sep 30 16:34:01 localhost CROND[1874]
Sep 30 16:35:01 localhost CROND[1936]
Sep 30 16:36:01 localhost CROND[1995]
Sep 30 16:37:01 localhost CROND[2062]

Scheduler log:

2018-09-30 16:20:12] production.INFO: schedule call  
[2018-09-30 16:21:01] production.INFO: schedule call  
[2018-09-30 16:22:02] production.INFO: schedule call  
[2018-09-30 16:23:01] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:28:01] production.INFO: schedule call  
[2018-09-30 16:29:01] production.INFO: schedule call  
[2018-09-30 16:30:01] production.INFO: schedule call  
[2018-09-30 16:31:01] production.INFO: schedule call  
[2018-09-30 16:32:02] production.INFO: schedule call  
[2018-09-30 16:33:01] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  

Charrua started a new conversation Scheduler Running With Delay (not On Time) • 2 weeks ago

Laravel 5.5 PHP 7.1

I have a strange issue on production server that delays the scheduler so tasks are not fired on time. It seems that for some reason the command artisan schedule:run sometimes takes time to load. If I run artisan schedule:run from console, it runs immediately, the issue is when is fired with the cron job. I have set the cron to fire by 5 minutes instead of all minutes to see more clear.

Cron log:

Sep 29 10:05:01 localhost CROND[17311]
Sep 29 10:10:01 localhost CROND[17846]
Sep 29 10:15:01 localhost CROND[18165]

Scheduler log:

Received ping at Saturday, 29-Sep-2018 10:06:11 EDT 
Received ping at Saturday, 29-Sep-2018 10:10:01 EDT 
Received ping at Saturday, 29-Sep-2018 10:18:55 EDT

The only task the scheduler has is a simple closure to measure time, no complex tasks.

$schedule->call(function () {
            return true;
        })
        ->everyMinute()
        ->pingBefore('...')

Somebody told me this could be a server load issue or clock sync, after running uptime; sar -q; etc the results are 10:52:05 up 4:29, 1 user, load average: 0,02, 0,04, 0,05 and clock is on sync.

The real issue is that if I have a task set to run eg at 10:05, it never runs, because the scheduler is loaded at 10:06.

Any ideas?

28th September, 2018

Charrua left a reply on Scheduler Running Strange • 2 weeks ago

@Snapey I agree with you is like queuing somewhere, I'm not queuing mail, and if you see the code I'm using thenPing() function and the time registry in cronhub (cron monitor) is the same.

Charrua left a reply on Scheduler Running Strange • 2 weeks ago

te issue is when running scheduler at a digital ocean server, if I run it locally no problems. Any ideas?

Charrua started a new conversation Scheduler Running Strange • 2 weeks ago

Hello I have a really strange issue in scheduler, sometimes runs the same task for two or three times.. I don't really know what is happening, if there is a server issue or anything else...

This is my simple scheduler code:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [

    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        
        $schedule->call(function () {
            return true;
        })->everyMinute()->emailOutputTo('...')->thenPing('https://cronhub.io/ping/af709030-c0e8-11e8-9b2f-ff58704a871a');

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

Te last outputs where:

19.06
19.07
19.08
19.09
19.10
19.11
19.12
19.13

19.16
19.16
19.16

19.17
19.18

19.21
19.21
19.21

19.22
19.23

19.25
19.25

19.26

Charrua left a reply on Scheduler Only Running Some Tasks • 2 weeks ago

@D9705996 so here I am again, with fresh results.

The tasks are run twice and out of four, only three have run.

Really no clue here in what is going on.

The actual scheduler code is:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\Appointments\AppCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppDayBeforeComm::class,
        \App\Console\Commands\Appointments\AppIntroCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppIntroDayBeforeComm::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        
        //appointments notification group A (vip - new)
        $schedule->command('appt:intro-day-before')->dailyAt('11:35')->emailOutputTo('email');

        $schedule->command('appt:intro-current-day')
                        ->dailyAt('11:30')
                        ->emailOutputTo('email');
                       
        //appointments notification group B (all others and goal appointments)
        $schedule->command('appt:day-before')->dailyAt('11:50')->emailOutputTo('email');

        $schedule->command('appt:current-day')
                        ->dailyAt('11:45')
                        ->emailOutputTo('email');       

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

Charrua left a reply on Scheduler Only Running Some Tasks • 2 weeks ago

@D9705996 yesterday I have deleted the php path and project filesystem artisan to post here, my original cron is:

* * * * *   /opt/plesk/php/7.1/bin/php /var/www/vhosts/DOMAIN/laravel/artisan schedule:run >> /dev/null 2>&1

I'll wait for today and see if the commands are fired on time, without any skip or withoutOverlapping functions.

If I run php artisan schedule:runon project folder I see only No scheduled commands are ready to run.

27th September, 2018

Charrua left a reply on Scheduler Only Running Some Tasks • 2 weeks ago

@D9705996 confirmed I'm using

* * *   * * php artisan schedule:run >> /dev/null 2>&1

If I run directly php artisan schedule:run I get no errors and No scheduled commands are ready to run.

I will try to temporarily remove skip and withoutOverlap functions to see what is the result, thank you for the Carbon use to be more readable. I have implemented the withoutOverlap because some commands were running duplicate. But I will try it again and see.

@Snapey I don't see any errors in the Laravel Log. I think this is easy to search in logs as I don't have any error at the time of the execution of the commands that do not run.

Charrua started a new conversation Scheduler Only Running Some Tasks • 2 weeks ago

I have my kernel.php to run some artisan commands but it runs only some of them. Any ideas why is this happening? I can run commands without any issues from console.

The commands that run today: 11.35 appt:intro-day-before 11.45 appt:current-day

All commands get a list of members and send email.

This is my file:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\Appointments\AppCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppDayBeforeComm::class,
        \App\Console\Commands\Appointments\AppIntroCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppIntroDayBeforeComm::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        

        //appointments notification group A (vip - new)
        $schedule->command('appt:intro-day-before')
            ->dailyAt('11:35')
            ->withoutOverlapping()
            ->emailOutputTo('...');

        $schedule->command('appt:intro-current-day')
                        ->dailyAt('11:30')
                        ->skip(function () {
                            return date('N') == 6; //skip on saturday
                        })->withoutOverlapping()
                        ->emailOutputTo('...');
                        
            
        //appointments notification group B (all others and goal appointments)
        $schedule->command('appt:day-before')
            ->dailyAt('11:50')
            ->withoutOverlapping()
            ->emailOutputTo('...');

        $schedule->command('appt:current-day')
                        ->dailyAt('11:45')
                        ->skip(function () {
                            return date('N') == 6; //skip on saturday
                        })
                        ->withoutOverlapping()
                        ->emailOutputTo('...');        

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }

}

26th September, 2018

Charrua left a reply on Scheduler Running Some Tasks Twice • 2 weeks ago

is more strange even, I have studied the emails results, log results and real life. The email result is the same as the real life, the log results are not all written to file. So the tasks executed where

05.00 auto:fill-twilio-sms
11.30 appt:intro-current-day
11.35 appt:intro-day-before
11.50 appt:day-before

And the only one that was not executed was 11.45 appt:current-day

Maybe is still running from yesterday but how could I know that? What tasks are still running?

Charrua left a reply on Scheduler Running Some Tasks Twice • 2 weeks ago

@aurawindsurfing there are really 5 tasks here, two that run different on saturday. For example today with the code published the task that run where

05.00 auto:fill-twilio-sms
11.30 appt:intro-current-day
11.35 appt:intro-day-before
11.50 appt:day-before

the one that never run was appt:current-day

The tries per task that I have setup in supervisor are one. Maybe the task is still running from yesterday and because of that never runs today. The issue is that today no duplicate tasks run, but a task was never executed. This task send emails to the queue, some maybe have errors, but they are deleted from the current job table because they have set only one try.

Charrua started a new conversation Scheduler Running Some Tasks Twice • 2 weeks ago

I have some tasks on Kernel.php scheduler to run on different times, the problem is that some of them, not all, runs twice. I'm also using supervisor with 2 processes.

My Kernel.php:

´´´

20th August, 2018

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo • 1 month ago

problem solved creating a custom channel and a service provider to resolve NexmoCustomSmsChannel class.

Charrua left a reply on Creating Nexmo Custom Notification Channel • 1 month ago

For someone looking for this answer, the problem was that I needed a service provider for NexmoCustomSmsChannel class to resolve.

18th August, 2018

Charrua started a new conversation Creating Nexmo Custom Notification Channel • 1 month ago

Hello, I'm creating a new Nexmo notification channel because I need to add some client-ref parameter to the Nexmo API request.

The original channel that packs with Laravel 5.6 has a send method:

/**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }
        $message = $notification->toNexmo($notifiable);
        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }
        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
        ]);
    }

I need to add the parameter as:

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
        'client-ref' => 'some text...',
        ]);

So I tried to duplicate the channel and instantiate it as Laravel documentation on creating custom channel (https://laravel.com/docs/5.6/notifications#custom-channels)

I have created NexmoCustomSmsChannel and only add my parameter, so the final channel is a duplicate from the original only with one extra parameter:

<?php

namespace App\Channels;

use Nexmo\Client as NexmoClient;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\NexmoMessage;


class NexmoCustomSmsChannel 
{
    /**
     * The Nexmo client instance.
     *
     * @var \Nexmo\Client
     */
    protected $nexmo;

    /**
     * The phone number notifications should be sent from.
     *
     * @var string
     */
    protected $from;

    /**
     * Create a new Nexmo channel instance.
     *
     * @param  \Nexmo\Client  $nexmo
     * @param  string  $from
     * @return void
     */
    public function __construct(NexmoClient $nexmo, $from)
    {
        $this->from = $from;
        $this->nexmo = $nexmo;
    }

    /**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }

        $message = $notification->toVoice($notifiable);

        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
            'client-ref' =>  'some text...',
        ]);
    }
}

And my notification is like:

<?php

namespace App\Notifications\Appointments;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

use App\Channels\NexmoCustomSmsChannel;


class AppIntroNew extends Notification implements ShouldQueue
{
    use Queueable;


    private $appointment;


    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($appointment)
    {
        $this->appointment = $appointment;
    }



    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [NexmoCustomSmsChannel::class];
    }



    /**
     * Get the Nexmo / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toVoice($notifiable)
    {
        return (new NexmoMessage)->content('some sms content.');
    }
    
}

The error I get is:

[2018-08-18 04:23:58] local.ERROR: Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. at /Users/.../Documents/Web/.../app/vendor/laravel/framework/src/Illuminate/Container/Container.php:918)

Any ideas?

17th August, 2018

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo • 1 month ago

@crnkovic I have created App\Channels\NexmoCustomSmsChannel and copied the code, added the parameter I need but I get an error.

My Nexmo custom channel looks like this:

namespace App\Channels;

use Nexmo\Client as NexmoClient;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\NexmoMessage;

class NexmoCustomSmsChannel 
{
    /**
     * The Nexmo client instance.
     *
     * @var \Nexmo\Client
     */
    protected $nexmo;

    /**
     * The phone number notifications should be sent from.
     *
     * @var string
     */
    protected $from;

    /**
     * Create a new Nexmo channel instance.
     *
     * @param  \Nexmo\Client  $nexmo
     * @param  string  $from
     * @return void
     */
    public function __construct(NexmoClient $nexmo, $from)
    {
        $this->from = $from;
        $this->nexmo = $nexmo;
    }

    /**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }

        $message = $notification->toVoice($notifiable);

        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
            'client-ref' => $message->client_ref,
        ]);
    }
}

And the error I get is:

[2018-08-17 12:22:10] local.ERROR: Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. at /Users/.../Documents/Web/.../app/vendor/laravel/framework/src/Illuminate/Container/Container.php:918)

Any ideas?

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo • 1 month ago

@crnkovic I have also found that file and my understanding is like you said, this method is only sending those parameters, so maybe I need to duplicate this channel as you said and add the client-ref parameter and test.

Maybe this has an easiest way but I cant find any on the web...

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo • 1 month ago

Yes I understand that, but I'm looking for a way to do it inside the notification (I'm also listening to some events)

Something like return (new NexmoMessage)->content('text')->clientRef('25');

Charrua started a new conversation Use ClientRef Value When Sending SMS With Nexmo • 1 month ago

Hello, I'm using SMS notification alerts using Nexmo. Searching their API I can see a custom information field that I can use for sending additional information attached to the SMS, this is the client-ref.

You can see it here 'https://developer.nexmo.com/api/sms#send-an-sms' under 'Request body'

This is my notification code:

    /**
         * Get the Nexmo / SMS representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return NexmoMessage
         */
        public function toNexmo($notifiable)    {
            
    return (new NexmoMessage)->content('Congratulations! You have an appt with .... Please text C to CONFIRM.');

        }

Any ideas in how to send also the client-ref parameter?

13th August, 2018

Charrua left a reply on Trigger Notification On Bulk Insert • 2 months ago

@wilburpowery unfortunately ModelName::create($array-of-data) only creates one at a time, remember I need to create a bulk insert. And ModelName::insert($array-of-data) doesn't fire any events:

Model doesn't have an insert method. Calling Model::insert results in a call to Builder::insert through the __call() magic method.

As I need to insert a maximum of 20 bulk records, I ended up by doing:

foreach ($array-of-data as $item){
    $appointment = \App\GoalAppointment::create($item);
    $appointment->notify(new AppNew($appointment));
}

10th August, 2018

Charrua left a reply on Trigger Notification On Bulk Insert • 2 months ago

@wilburpowery great but instead to use an event, can I fire the notification directly from that method?

For example:

public static function boot()
{
    parent::boot();
    
    static::created(function ($appointment) {
        $appointment->notify(new AppIntroNew($appointment));
    })
}

@Cronix I understand that using DB query builder does not fire any model events. I need to create in some way a bulk insert, lets say 100 records... Why would be the Eloquent way? I have found some information on using ModelName::insert($array);, this would be the Eloquent way? and this will trigger the create method that @wilburpowery refers to? Or this will trigger the event and therefore I need to create the listener with the notification fire?

Thank you both.

9th August, 2018

Charrua started a new conversation Trigger Notification On Bulk Insert • 2 months ago

Hi, I'm actually saving into the database appointments by inserting them in bulk.

DB::table('goals_appointments')->insert( $appointments_array );

Is there a way to trigger a notification to each appointment inserted?

30th July, 2018

Charrua left a reply on Limit Queued Notification Tries • 2 months ago

maybe I found a easiest solution but is for all jobs. I'm running php artisan queue:work --tries=1and this will do the job, for now...

Thank you @lostdreamer_nl for your help.

Charrua left a reply on Limit Queued Notification Tries • 2 months ago

Hey @lostdreamer_nl thank you for that piece of code! seems logic. But I'm wondering if there is an easiest way to accomplish this, maybe pass in some other way the $tries value to Illuminate\Mail\SendQueuedMailable class inside the notification class... I have to do this to SMS notifications and so on.. So I'm looking for an easiest way (if is one)

27th July, 2018

Charrua left a reply on Limit Queued Notification Tries • 2 months ago

I have added that public method but no luck. This is my notification:

class AppIntroCurrentDay extends Notification implements ShouldQueue
{
    use Queueable;

    private $appointment;

    public function maxTries()
    {
        return 5;
    }


    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($appointment)
    {
        $this->appointment = $appointment;
    }


    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return Mailable
     */
    public function toMail($notifiable)
    {
        return (new Mailable($this->appointment))->to($this->appointment->email);
    }
    
}

And the job that is created in the jobs table: As you can see there is a "maxTries":null,

{"displayName":"App\Notifications\Appointments\AppIntroCurrentDay","job":"Illuminate\Queue\[email protected]","maxTries":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"Illuminate\Notifications\SendQueuedNotifications","command":"O:48:\"Illuminate\Notifications\SendQueuedNotifications\":9:{s:11:\"notifiables\";O:45:\"Illuminate\Contracts\Database\ModelIdentifier\":3:{s:5:\"class\";s:15:\"App\Appointment\";s:2:\"id\";i:866;s:10:\"connection\";s:5:\"mysql\";}s:12:\"notification\";O:49:\"App\Notifications\Appointments\AppIntroCurrentDay\":9:{s:62:\"\u0000App\Notifications\Appointments\AppIntroCurrentDay\u0000appointment\";O:45:\"Illuminate\Contracts\Database\ModelIdentifier\":3:{s:5:\"class\";s:15:\"App\Appointment\";s:2:\"id\";i:866;s:10:\"connection\";s:5:\"mysql\";}s:2:\"id\";s:36:\"26b0504d-bb22-4098-a8ec-80d65b09bbcc\";s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:7:\"chained\";a:0:{}s:6:\"\u0000*\u0000job\";N;}s:8:\"channels\";a:1:{i:0;s:5:\"nexmo\";}s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:7:\"chained\";a:0:{}}"}}

Charrua started a new conversation Limit Queued Notification Tries • 2 months ago

I want to define a limit to try each queued notifications. For example when writing a job class, I use $tries to define maxTries for that queued job, but I don't know how to implement this using queued notifications.

Any ideas?

25th July, 2018

Charrua started a new conversation Get Nexmo SMS Notification API Response • 2 months ago

Hello, I'm using nexmo SMS notifications and wanted to get the nexmo API response when I send an SMS to get the ID (of the message) and then store it with some model ID for example.

The main purpose is then to get the nexmo delivery status of the message and assign it to that model also...

In my notification class I use:

public function via($notifiable)
    {
        return ['mail', 'nexmo'];
    }

    
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return Mailable
     */
    public function toMail($notifiable)
    {
        return (new Mailable($this->appointment))->to($this->appointment->email);
    }



    /**
     * Get the Nexmo / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toNexmo($notifiable)
    {
        return (new NexmoMessage)
                    ->content('Test SMS');
    }

10th July, 2018

Charrua left a reply on How To Add Custom Headers To Notification Emails? • 3 months ago

Hello @squibby I have the same problem, I want to send notifications and attach a custom header with model id, how do you solve this? I have my code for mail notification but I cant find a way to attach the header.

public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->greeting('Hello ' . $this->appointment->customer)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

9th July, 2018

Charrua started a new conversation Custom Headers On Email Notifications • 3 months ago

Hey I wanted to set custom header with model id for example in my emails to later store the maligun response through webhooks.

I have tried many solutions found on the web but none suits my needs.

A solution I have tried is: https://stackoverflow.com/a/43653673/7274497 but this attaches a custom header to any of the emails sent through laravel and not only for specific notifications (that is what I need).

I have also investigate MailMessageand SimpleMessageclasses that are present on the notification class but I cant find a way to attach custom headers.

public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->greeting('Hello ' . $this->appointment->customer)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

Any ideas?

Charrua left a reply on Model Notes (like Activity Log) • 3 months ago

Great answer @Jarrid, initially I was thinking in something like this but the downside was that I thought when cleaning the log it will clean all logs, but investigating the code I have found that we can clean up a particular log instead of all logs... That's not in documentation.

protected $signature = 'activitylog:clean
                            {log? : (optional) The log name that will be cleaned.}';

So I will be using this Laravel package for my model notes.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.