<?php

namespace App\Modules\Network\Commands;

use App\Helpers\Utility\GoliathBgp;

class GoliathWithdraw extends \App\Console\Commands\BaseCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'goliath:withdraw';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Sets up goliath objects for all prefixes.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $start = microtime(true);

        $max = 6;

        $pipe = [];
            
        for ($i = 0; $i < $max; ++$i) {
            $pipe[$i] = popen("php /var/www/html/creatia/artisan goliath:withdraw-thread --as-max=$max --as-mod=$i", 'w');
        }
        
        for ($i = 0; $i < $max; ++$i) {
            pclose($pipe[$i]);
        }

        \Log::debug("Withdrawal execution: " . (microtime(true) - $start));

        return 0;
    }
}