2016-01-09 13 views
7

Ho difficoltà a capire cosa sta succedendo esattamente con la mia app Laravel. Funziona perfettamente a livello locale (Mac, php 5.5.26), quindi ho testato l'app sul mio droplet digitale attraverso forge (php 5.6.15).Numero di merge non armoniche di Laravel

Sto utilizzando this package per inviare notifiche push all'app di front-end che consuma il mio Laravel api. Per rendere più veloci le chiamate a API, ho delegato le notifiche push alle code di Laravel che funzionano molto bene localmente, ma ho ricevuto questo errore quando ho provato su digital ocean.

[2016-01-09 20:34:09] stage.ERROR: exception 'ErrorException' with message 'Erroneous data format for unserializing 'ArrayIterator'' in {path}/{project}/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:74 

Sto utilizzando il driver del database. Ecco la fila lavoro serializzato nella mia tabella di lavoro di database locale ...

{"job":"Illuminate\\Queue\\[email protected]","data":{"command":"O:28:\"App\\Jobs\\Push\\SendPushFollow\":4:{s:34:\"\u0000App\\Jobs\\Push\\SendPushFollow\u0000push\";O:27:\"App\\Helpers\\Push\\PushFollow\":5:{s:14:\"\u0000*\u0000ios_devices\";O:50:\"Sly\\NotificationPusher\\Collection\\DeviceCollection\":1:{s:7:\"\u0000*\u0000coll\";C:13:\"ArrayIterator\":21:{x:i:0;a:0:{};m:a:0:{}}}s:16:\"\u0000*\u0000android_count\";i:2;s:12:\"\u0000*\u0000ios_count\";i:0;s:18:\"\u0000*\u0000android_devices\";O:50:\"Sly\\NotificationPusher\\Collection\\DeviceCollection\":1:{s:7:\"\u0000*\u0000coll\";C:13:\"ArrayIterator\":953:{x:i:0;a:2:{s:162:\"APA91bGCWGMQlh6kMYVVPUjnkDKtgLmYBiHxv1WY4r3zPjmXO3C0_UcvBCoOWkiiiC8lBc4JRILBDo29K0BtGNQKKQAA46tCvJocklTp3u7_x4q8Nz9CubNuqJN_OaMRBys_HWUqNXPLzIbodjEHV_bTc-CUKurnRQ\";O:35:\"Sly\\NotificationPusher\\Model\\Device\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Device\u0000token\";s:162:\"APA91bGCWGMQlh6kMYVVPUjnkDKtgLmYBiHxv1WY4r3zPjmXO3C0_UcvBCoOWkiiiC8lBc4JRILBDo29K0BtGNQKKQAA46tCvJocklTp3u7_x4q8Nz9CubNuqJN_OaMRBys_HWUqNXPLzIbodjEHV_bTc-CUKurnRQ\";s:13:\"\u0000*\u0000parameters\";a:0:{}}s:162:\"APA91bEUPnqR3t8KDhE0YTsc_HnkoxFvw4WyUpRxISm2A_2Ep7orCySVKsh2oRVSQTVOhSZS_yYjP7gup5vEnuwz2JPXcxHCc19P98E2QVNyjhTP_NvDkcfkogVIHAHpgelyGRuvm8aQ-SAs9uirxd3iBHPlZb16zA\";O:35:\"Sly\\NotificationPusher\\Model\\Device\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Device\u0000token\";s:162:\"APA91bEUPnqR3t8KDhE0YTsc_HnkoxFvw4WyUpRxISm2A_2Ep7orCySVKsh2oRVSQTVOhSZS_yYjP7gup5vEnuwz2JPXcxHCc19P98E2QVNyjhTP_NvDkcfkogVIHAHpgelyGRuvm8aQ-SAs9uirxd3iBHPlZb16zA\";s:13:\"\u0000*\u0000parameters\";a:0:{}}};m:a:0:{}}}s:10:\"\u0000*\u0000message\";O:36:\"Sly\\NotificationPusher\\Model\\Message\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Message\u0000text\";s:32:\"John Smith is now following you!\";s:10:\"\u0000*\u0000options\";a:12:{s:5:\"badge\";i:1;s:5:\"sound\";s:12:\"example.aiff\";s:12:\"actionLocKey\";s:20:\"Action button title!\";s:6:\"locKey\";s:13:\"localized key\";s:7:\"locArgs\";a:2:{i:0;s:14:\"localized args\";i:1;s:14:\"localized args\";}s:11:\"launchImage\";s:9:\"image.jpg\";s:5:\"title\";s:21:\"InMyBag: New Follower\";s:6:\"custom\";a:0:{}s:5:\"notId\";i:7;s:5:\"style\";s:5:\"inbox\";s:8:\"ledColor\";a:4:{i:0;i:0;i:1;i:0;i:2;i:255;i:3;i:0;}s:16:\"vibrationPattern\";a:3:{i:0;i:500;i:1;i:250;i:2;i:500;}}}}s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}"}} 

Ed ecco la voce di riga dalla tabella server ...

{"job":"Illuminate\\Queue\\[email protected]","data":{"command":"O:28:\"App\\Jobs\\Push\\SendPushFollow\":4:{s:34:\"\u0000App\\Jobs\\Push\\SendPushFollow\u0000push\";O:27:\"App\\Helpers\\Push\\PushFollow\":5:{s:14:\"\u0000*\u0000ios_devices\";O:50:\"Sly\\NotificationPusher\\Collection\\DeviceCollection\":1:{s:7:\"\u0000*\u0000coll\";O:13:\"ArrayIterator\":0:{}}s:16:\"\u0000*\u0000android_count\";i:2;s:12:\"\u0000*\u0000ios_count\";i:0;s:18:\"\u0000*\u0000android_devices\";O:50:\"Sly\\NotificationPusher\\Collection\\DeviceCollection\":1:{s:7:\"\u0000*\u0000coll\";O:13:\"ArrayIterator\":2:{s:162:\"APA91bGCWGMQlh6kMYVVPUjnkDKtgLmYBiHxv1WY4r3zPjmXO3C0_UcvBCoOWkiiiC8lBc4JRILBDo29K0BtGNQKKQAA46tCvJocklTp3u7_x4q8Nz9CubNuqJN_OaMRBys_HWUqNXPLzIbodjEHV_bTc-CUKurnRQ\";O:35:\"Sly\\NotificationPusher\\Model\\Device\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Device\u0000token\";s:162:\"APA91bGCWGMQlh6kMYVVPUjnkDKtgLmYBiHxv1WY4r3zPjmXO3C0_UcvBCoOWkiiiC8lBc4JRILBDo29K0BtGNQKKQAA46tCvJocklTp3u7_x4q8Nz9CubNuqJN_OaMRBys_HWUqNXPLzIbodjEHV_bTc-CUKurnRQ\";s:13:\"\u0000*\u0000parameters\";a:0:{}}s:162:\"APA91bEUPnqR3t8KDhE0YTsc_HnkoxFvw4WyUpRxISm2A_2Ep7orCySVKsh2oRVSQTVOhSZS_yYjP7gup5vEnuwz2JPXcxHCc19P98E2QVNyjhTP_NvDkcfkogVIHAHpgelyGRuvm8aQ-SAs9uirxd3iBHPlZb16zA\";O:35:\"Sly\\NotificationPusher\\Model\\Device\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Device\u0000token\";s:162:\"APA91bEUPnqR3t8KDhE0YTsc_HnkoxFvw4WyUpRxISm2A_2Ep7orCySVKsh2oRVSQTVOhSZS_yYjP7gup5vEnuwz2JPXcxHCc19P98E2QVNyjhTP_NvDkcfkogVIHAHpgelyGRuvm8aQ-SAs9uirxd3iBHPlZb16zA\";s:13:\"\u0000*\u0000parameters\";a:0:{}}}}s:10:\"\u0000*\u0000message\";O:36:\"Sly\\NotificationPusher\\Model\\Message\":2:{s:42:\"\u0000Sly\\NotificationPusher\\Model\\Message\u0000text\";s:32:\"John Smith is now following you!\";s:10:\"\u0000*\u0000options\";a:12:{s:5:\"badge\";i:1;s:5:\"sound\";s:12:\"example.aiff\";s:12:\"actionLocKey\";s:20:\"Action button title!\";s:6:\"locKey\";s:13:\"localized key\";s:7:\"locArgs\";a:2:{i:0;s:14:\"localized args\";i:1;s:14:\"localized args\";}s:11:\"launchImage\";s:9:\"image.jpg\";s:5:\"title\";s:21:\"InMyBag: New Follower\";s:6:\"custom\";a:0:{}s:5:\"notId\";i:10;s:5:\"style\";s:5:\"inbox\";s:8:\"ledColor\";a:4:{i:0;i:0;i:1;i:0;i:2;i:255;i:3;i:0;}s:16:\"vibrationPattern\";a:3:{i:0;i:500;i:1;i:250;i:2;i:500;}}}}s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}"}} 

ho eseguito un dif di testo on-line e scoperto che la porzione di dati serializzata di quel blob presenta un paio di differenze che si verificano (come indicato dai log degli errori) nella parte ArrayIterator. Sembra che la differenza provenga dal modo in cui l'oggetto PushNotification :: DeviceCollection è serializzato differisce tra la mia macchina locale e il server. Nel mio test ho colpito l'endpoint api localmente e sul server con gli stessi dati POST per assicurarmi che l'output del serialize sia lo stesso ma non lo è.

Non sono davvero sicuro di come risolvere il problema. Non so se questo è tecnicamente un bug con il pacchetto PushNotification (non ho visto segnalazioni di bug relative a questo problema) o se è solo qualcos'altro su cui sto riflettendo.

Inoltre, solo una nota a margine, sto usando un'altra coda per inviare eventi KeenIO utilizzando una struttura di classe simile a questa struttura Push e non ha alcun problema quindi mi sento davvero come se dovesse esserci un problema con PushNotification pacchetto in qualche modo ... Qualche idea ??


risolto

Così si scopre che è stato un problema con la versione di PHP. Il mio server era in esecuzione 5.6 e quando ho creato un'altra gocciolina su PHP 7.0 e clonato il server, tutto ha iniziato a funzionare. Ho lasciato il server originale attivo e funzionante in modo che potesse funzionare come un processore di coda per le notifiche push che utilizza beanstalkd e funziona come un campione.


EDIT

Sto usando supervisore per eseguire la coda: comando di lavoro. Ho eseguito

php artisan queue:restart 

e ho fatto in modo che il processo artigianale è completamente interrotta quando si esegue un nuovo test per l'esecuzione di un comando kill tramite linea di comando. Anche in questo caso l'addetto alla coda non ha problemi con i miei lavori KeenIO sul server, solo i lavori PushNotification.

Ecco la categoria di lavoro:

<?php namespace App\Jobs\Push; 

use Illuminate\Queue\SerializesModels; 
use Illuminate\Queue\InteractsWithQueue; 
use Illuminate\Contracts\Bus\SelfHandling; 
use Illuminate\Contracts\Queue\ShouldQueue; 
use App\Jobs\SendPushEvent; 
use App\Helpers\Push\PushFollow; 

class SendPushFollow extends SendPushEvent implements SelfHandling, ShouldQueue { 
    use InteractsWithQueue, SerializesModels; 
    private $push; 
    /** 
    * Create a new job instance. 
    * 
    * @return void 
    */ 
    public function __construct($follower, $followee) 
    { 
     $this->push = new PushFollow($follower, $followee); 
    } 

    /** 
    * Execute the job. 
    * 
    * @return void 
    */ 
    public function handle(){ 
     $this->push->send(); 
    } 
} 

Ed ecco la classe PushFollow che ha tutta la logica PushNotification in esso.

<?php namespace App\Helpers\Push; 

use PushNotification; 
use App\Helpers\Push\Push; 
use Log; 

class PushFollow extends Push { 
    /** 
    * This builds the default notification. 
    * @param array $data the passed in data array 
    * @param [type] $type android or iOS 
    */ 
    public function __construct ($follower, $followee) { 
     $_ios_devices = []; 
     $_android_devices = []; 
     $this->ios_count = 0; 
     $this->android_count = 0; 

     foreach($followee->devices as $_device){ 
      if($_device->platform == "ios"){ 
       $_ios_devices[] = PushNotification::Device($_device->identifier); 
       $this->ios_count++; 
      } elseif ($_device->platform == "android") { 
       $_android_devices[] = PushNotification::Device($_device->identifier); 
       $this->android_count++; 
      } 
     } 

     Log::info('FINISHED BUILDING THE LISTS!!!'); 

     $this->ios_devices = PushNotification::DeviceCollection($_ios_devices); 
     $this->android_devices = PushNotification::DeviceCollection($_android_devices); 

     Log::info('SET THE DEVICE COLLECTIONS'); 

     $this->message = PushNotification::Message($follower->profile->name.' is now following you!',[ 
      'badge' => 1, 
      'sound' => 'example.aiff', 
      'actionLocKey' => 'Action button title!', 
      'locKey' => 'localized key', 
      'locArgs' => array(
       'localized args', 
       'localized args', 
      ), 
      'launchImage' => 'image.jpg', 
      'title' => env('APP_NAME').': New Follower', 
      'custom' => [], 
      'notId' => rand(1, 20), 
      'style' => 'inbox', 
      /* 
      'actions' => [ 
       ['icon' => "emailGuests", 'title' => "EMAIL GUESTS", 'callback' => "app.emailGuests"], 
       [ 'icon' => "snooze", 'title' => "SNOOZE", 'callback' => "app.snooze"], 
      ], 
      */ 
      'ledColor' => [0, 0, 255, 0], 
      'vibrationPattern' => [500, 250, 500], 

     ]); 

     Log::info('SET THE MESSAGE'); 
    } 

    public function send() { 
     Log::info('CALLING THE SEND METHOD'); 
     if($this->android_count) { 
      PushNotification::app(env('ANDROID_PUSH_NAME')) 
       ->to($this->android_devices) 
       ->send($this->message); 
     } 

     if($this->ios_count){ 
      PushNotification::app(env('IOS_PUSH_NAME')) 
       ->to($this->ios_devices) 
       ->send($this->message); 
     } 
    } 
} 

Ed ecco la classe di spinta che tutte le mie diverse classi di spinta si estendono.

<?php namespace App\Helpers\Push; 

abstract class Push { 
    protected $ios_devices; 
    protected $android_count; 
    protected $ios_count; 
    protected $android_devices; 
    protected $message; 
} 

Oh ed ecco anche la traccia dello stack.

#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Erroneous data ...', '/home/forge/def...', 74, Array) 
#1 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(74): unserialize('O:28:"App\\Jobs\\...') 
#2 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(212): Illuminate\Queue\CallQueuedHandler->failed(Array) 
#3 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(261): Illuminate\Queue\Jobs\Job->failed() 
#4 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(201): Illuminate\Queue\Worker->logFailedJob('database', Object(Illuminate\Queue\Jobs\DatabaseJob)) 
#5 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(159): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), '5', 0) 
#6 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(111): Illuminate\Queue\Worker->pop(NULL, 'keen,push_notif...', 0, 3, '5') 
#7 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(87): Illuminate\Queue\Worker->runNextJobForDaemon(NULL, 'keen,push_notif...', 0, 3, '5') 
#8 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(103): Illuminate\Queue\Worker->daemon(NULL, 'keen,push_notif...', 0, 128, 3, '5') 
#9 {path_to_project}/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(71): Illuminate\Queue\Console\WorkCommand->runWorker(NULL, 'keen,push_notif...', 0, 128, true) 
#10 [internal function]: Illuminate\Queue\Console\WorkCommand->fire() 
#11 {path_to_project}/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array) 
#12 {path_to_project}/vendor/laravel/framework/src/Illuminate/Console/Command.php(150): Illuminate\Container\Container->call(Array) 
#13 {path_to_project}/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#14 {path_to_project}/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#15 {path_to_project}/vendor/symfony/console/Application.php(837): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#16 {path_to_project}/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#17 {path_to_project}/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#18 {path_to_project}/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#19 {path_to_project}/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) 
#20 {main} 
+0

Stai demonizzando il processo? Se stai usando qualcosa come Upstart o Supervisord, hai provato a resettare il demone? So che se si modifica lo script dopo aver eseguito il comando daemon, è necessario ripristinarlo, altrimenti non raccoglierà le modifiche. – maiorano84

+0

@ maiorano84 vedi la mia modifica. – Panda4Man

risposta

1

Quindi si è verificato un problema con la versione di PHP. Il mio server era in esecuzione 5.6 e quando ho creato un'altra gocciolina su PHP 7.0 e clonato il server, tutto ha iniziato a funzionare. Ho lasciato il server originale attivo e funzionante in modo che potesse funzionare come un processore di coda per le notifiche push che utilizza beanstalkd e funziona come un campione.