Debug php extension load

Debug php extension load

dl — Loads a PHP extension at runtime

Описание

Loads the PHP extension given by the parameter library.

Use extension_loaded() to test whether a given extension is already available or not. This works on both built-in extensions and dynamically loaded ones (either through php.ini or dl() ).

This function has been removed from some SAPI’s in PHP 5.3.

Список параметров

This parameter is only the filename of the extension to load which also depends on your platform. For example, the sockets extension (if compiled as a shared module, not the default!) would be called sockets.so on Unix platforms whereas it is called php_sockets.dll on the Windows platform.

The directory where the extension is loaded from depends on your platform:

Windows — If not explicitly set in the php.ini , the extension is loaded from C:\php4\extensions\ (PHP4) or C:\php5\ (PHP5) by default.

  • whether PHP has been built with —enable-debug or not
  • whether PHP has been built with (experimental) ZTS (Zend Thread Safety) support or not
  • the current internal ZEND_MODULE_API_NO (Zend internal module API number, which is basically the date on which a major module API change happened, e.g. 20010901)

Возвращаемые значения

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки. If the functionality of loading modules is not available or has been disabled (either by setting enable_dl off or by enabling безопасный режим in php.ini ) an E_ERROR is emitted and execution is stopped. If dl() fails because the specified library couldn’t be loaded, in addition to FALSE an E_WARNING message is emitted.

Читайте также:  The jQuery Local Example

Примеры

Пример #1 dl() examples

// Example loading an extension based on OS
if (! extension_loaded ( ‘sqlite’ )) if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === ‘WIN’ ) dl ( ‘php_sqlite.dll’ );
> else dl ( ‘sqlite.so’ );
>
>

// Or, the PHP_SHLIB_SUFFIX constant is available as of PHP 4.3.0
if (! extension_loaded ( ‘sqlite’ )) $prefix = ( PHP_SHLIB_SUFFIX === ‘dll’ ) ? ‘php_’ : » ;
dl ( $prefix . ‘sqlite.’ . PHP_SHLIB_SUFFIX );
>
?>

Список изменений

Версия Описание
5.3.0 dl() is now disabled in some SAPI’s due to stability issues. The only SAPI’s that allow dl() are: CLI, CGI and Embed. Use the Extension Loading Directives instead.

Примечания

Замечание:

dl() is not supported when PHP is built with ZTS support. Use the Extension Loading Directives instead.

Замечание:

dl() is case sensitive on Unix platforms.

Смотрите также

Источник

Отладка php в Visual Studio Code (Xdebug, Windows)

В некоторых случаях может возникнуть необходимость отладки приложений на php. Visual Studio code предоставляет такую возможность при условии установки дополнительного расширения PHP Debug (marketplace, github).

Установка PHP Debug

Для установки нажмите Ctrl+p и введите команду ext install php-debug . Нажмите на кнопку «включить», в итоге вы должны увидеть примерно следующее:

image

Установка и настройка Xdebug

PHP Debug использует для отладки Xdebug. Для настройки Xdebug пройдите по ссылке. Предполагается, что на локальной машине уже установлен и настроен сервер apache. Здесь и далее действия указаны для Windows. Можно создать файл, например, test.php содержащий:

Открыть его в браузере и скопировать содержимое страницы в диалоговое окно. Другой способ:

  • win+R ;
  • cmd + Enter ;
  • php -i > phpinfo.text ;
  • открыть любым удобным редактором phpinfo.txt и все его содержимое вставить в диалоговое окно.
Читайте также:  Java split string and get last

Настройка Xdebug

Далее следуйте инструкциям по установке: скачайте .dll и не изменяя его имени скопируйте его в указанную папку, дополните файл php.ini указанной в руководстве строкой.

Кроме этого, добавьте нижеследующие строки. Итоговое добавление будет примерно таким:

 [XDebug] zend_extension = C:\xampp\php\ext\php_xdebug-2.4.1-5.6-vc11.dll xdebug.remote_enable=1 xdebug.remote_host=127.0.0.2 xdebug.remote_port=9000 xdebug.remote_autostart=on xdebug.remote_handler=dbgp xdebug.profiler_enable=1 xdebug.profiler_output_dir="C:\xampp\tmp" xdebug.remote_log ="C:\xampp\tmp\xdebug.log"

Как вы уже, возможно догадались, в данном примере на локальной машине установлен XAMPP.

Обратите внимание на строку xdebug.remote_host=127.0.0.2 . По умолчанию Xdebug «слушает» порт 127.0.0.1. Укажите здесь, адрес отлаживаемого сайта.

Примечание: С версией Xdebug 2.5 и выше Visual Studio code не работает. Поэтому выбирайте соответствующий вашей версии php файл *.dll.

Настройка Visual Studio code

Вызовите панель отладки (1) и нажмите на иконку с маленькой шестеренкой (2).

image

В появившемся списке выберите PHP . Автоматически сформируется файл launch.json .

Настройка PHP Debug на этом окончена.

Отладка php в Visual Studio code

Откройте в браузере ваше приложение\сайт. Откройте папку с приложением в Visual Studio code. Установите в нужных файлах и строках точки остановки. Откройте панель отладки и выберите для запуска отладки команду Listen for Xdebug (1). Нажмите кнопку запуска (2).

image

Обновите страницу в браузере и наслаждайтесь.

Источник

Оцените статью