I have Controller:
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(){}
public function index()
{
pcntl_fork();
}
}
Then I call index()
by HTTP request, And I get:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to undefined function App\Http\Controllers\pcntl_fork()
Then I try this:
class CodeSheet extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'code_sheet';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
pcntl_fork();
echo "1\n";
}
}
Then I call this command:
vagrant@homestead:~$ php artisan code_sheet
1
1
So my question is, Why I can call pcntl_fork()
in command, but can't in HTTP request?