xref: /PHP-8.3/sapi/cli/tests/ext_loading.phpt (revision c9e5e1fc)
1--TEST--
2Extension loading
3--SKIPIF--
4<?php
5$extDir = ini_get('extension_dir');
6if (!file_exists($extDir . '/opcache.so') && !file_exists($extDir . '/php_opcache.dll')) {
7    die('skip Opcache shared object not found in extension_dir');
8}
9?>
10--FILE--
11<?php
12
13function loadZendExt($extension) {
14    $cmd = [
15        PHP_BINARY, '-n',
16        '-dextension_dir=' . ini_get('extension_dir'),
17        '-dzend_extension=' . $extension,
18        '-r', 'echo "Done.";'
19    ];
20    $proc = proc_open($cmd, [['null'], ['pipe', 'w'], ['redirect', 1]], $pipes);
21    echo "#####OUTPUT_BEGIN####\n", stream_get_contents($pipes[1]), "\n######OUTPUT_END#####\n";
22}
23
24echo "Only extension name:\n";
25loadZendExt('opcache');
26
27echo "Name with file extension:\n";
28$name = PHP_OS_FAMILY == 'Windows' ? 'php_opcache.dll' : 'opcache.so';
29loadZendExt($name);
30
31echo "Absolute path:\n";
32$path = ini_get('extension_dir') . DIRECTORY_SEPARATOR . $name;
33loadZendExt($path);
34
35echo "Unknown extension name (unknown):\n";
36loadZendExt('unknown_ext');
37
38echo "Name with file extension (unknown):\n";
39$name = PHP_OS_FAMILY == 'Windows' ? 'php_unknown_ext.dll' : 'unknown_ext.so';
40loadZendExt($name);
41
42echo "Absolute path (unknown):\n";
43$path = ini_get('extension_dir') . DIRECTORY_SEPARATOR . $name;
44loadZendExt($path);
45
46?>
47--EXPECTF--
48Only extension name:
49#####OUTPUT_BEGIN####
50Done.
51######OUTPUT_END#####
52Name with file extension:
53#####OUTPUT_BEGIN####
54Done.
55######OUTPUT_END#####
56Absolute path:
57#####OUTPUT_BEGIN####
58Done.
59######OUTPUT_END#####
60Unknown extension name (unknown):
61#####OUTPUT_BEGIN####
62
63Warning: Failed loading Zend extension 'unknown_ext' (tried: %s) in Unknown on line 0
64Done.
65######OUTPUT_END#####
66Name with file extension (unknown):
67#####OUTPUT_BEGIN####
68
69Warning: Failed loading Zend extension '%Sunknown_ext%S' (tried: %s) in Unknown on line 0
70Done.
71######OUTPUT_END#####
72Absolute path (unknown):
73#####OUTPUT_BEGIN####
74Failed loading %s
75Done.
76######OUTPUT_END#####
77