How to check PCNTL module exists
Asked Answered
S

4

7

I write simple requirements checking script. It checks all required PHP modules installed. I need to check if pcntl is installed. But this module is accessible only in cgi environment and invisible for web queries. extension_loaded('pcntl') and function_exists('pcntl_fork') both return false. How can I perform this check?

Scrambler answered 11/6, 2013 at 18:7 Comment(3)
At the end of the day if function_exists('pcntl_fork') == false you can't use pcntl_forkSunbonnet
The problem is that if pcntl is present it still invisible until you run script without server, i.e. /usr/local/bin/php script.php. If you run script such method it will work fine. But if you want to check it from web like domain.com/req_check.php - there it will be hidden.Scrambler
The you are going to have to create a separate capability fishing script to get the capabilities from the CLI. you should be able to run that one from shell_exec and parse the returned data.Sunbonnet
S
4

Create a file called cli_supports.php

  <?php
  $supports = array();
  if (function_exists("pcntl_fork")) $supports[] = "pcntl";
  echo implode(",", $supports);
  ?>

Then from your feature detection scripts do.

  $cli_features = explode(",", shell_exec("/usr/local/bin/php ".escapeshellarg(_DIR_."/cli_supports.php")));
Sunbonnet answered 11/6, 2013 at 21:39 Comment(0)
J
20

Running php -i | grep pcntl will return the following if pcntl is enabled.

pcntl

pcntl support => enabled

Jailbird answered 30/10, 2018 at 5:41 Comment(0)
A
12

If it is installed, the code bellow returns true

var_dump (extension_loaded('pcntl'));
Ashton answered 11/7, 2014 at 9:42 Comment(0)
S
4

Create a file called cli_supports.php

  <?php
  $supports = array();
  if (function_exists("pcntl_fork")) $supports[] = "pcntl";
  echo implode(",", $supports);
  ?>

Then from your feature detection scripts do.

  $cli_features = explode(",", shell_exec("/usr/local/bin/php ".escapeshellarg(_DIR_."/cli_supports.php")));
Sunbonnet answered 11/6, 2013 at 21:39 Comment(0)
P
0

If you're sure it's supported (or shared object exists) then check your php.ini and make sure it's loaded as an extension.

extension_loaded() should work (and what I prefer over function_exists()), and the only reason I can imagine it wouldn't is you not loading the shared object.

Piston answered 25/2, 2014 at 23:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.