Работа с удалёнными файлами
В случае, если опция allow_url_fopen включена в конфигурационном файле php.ini , вы можете использовать URL-адреса HTTP и FTP в большинстве функций, принимающих в качестве параметра имя файла. Также вы можете использовать ссылки в операторах include , include_once , require и require_once (для корректной работы этих функций должна быть включена опция allow_url_include). Дополнительную информацию о поддерживаемых в PHP протоколах вы можете найти в Поддерживаемые протоколы и обёртки.
Например, вы можете использовать это для того, чтобы открыть файл на удалённом сервере, извлечь необходимые вам данные и использовать их в запросе к базе данных или же просто отобразить их в дизайне вашего сайта.
Пример #1 Получение заголовка удалённой страницы
$file = fopen ( «http://www.example.com/» , «r» );
if (! $file ) echo «
Невозможно открыть удалённый файл.\n» ;
exit;
>
while (! feof ( $file )) $line = fgets ( $file , 1024 );
/* Сработает, только если заголовок и сопутствующие теги расположены в одной строке */
if ( preg_match ( «@\(.*)\@i» , $line , $out )) $title = $out [ 1 ];
break;
>
>
fclose ( $file );
?>?php
Вы также можете работать с удалёнными файлами, расположенными на FTP-сервере (подразумевается, что вы авторизовались с необходимыми для этого привилегиями). Таким образом вы можете только создавать новые файлы, но попытка перезаписать существующий файл при помощи функции fopen() приведёт к ошибке.
Для того, чтобы авторизоваться под пользователем, отличным от ‘anonymous’, вам необходимо указать логин (и, возможно, пароль) в адресной строке, например так: ‘ ftp://user:password@ftp.example.com/path/to/file ‘. (Вы можете использовать этот же синтаксис для доступа к удалённым файлам по HTTP -протоколу, если необходима Basic-аутентификация.)
Пример #2 Сохранение данных на удалённом сервере
$file = fopen ( «ftp://ftp.example.com/incoming/outputfile» , «w» );
if (! $file ) echo «
Невозможно перезаписать удалённый файл.\n» ;
exit;
>
/* Запись данных. */
fwrite ( $file , $_SERVER [ ‘HTTP_USER_AGENT’ ] . «\n» );
fclose ( $file );
?>?php
Замечание:
Глядя на приведённый выше пример, у вас может возникнуть идея использовать эту технику для ведения удалённого лог-файла. К сожалению, это нереализуемо, поскольку попытка записи в уже существующий удалённый файл при помощи функции fopen() приведёт к ошибке. В реализации распределённого логирования, возможно, вам поможет функция syslog() .
User Contributed Notes
There are no user contributed notes for this page.
- Отличительные особенности
- HTTP-аутентификация в PHP
- Cookies
- Сессии
- Работа с XForms
- Загрузка файлов на сервер
- Работа с удалёнными файлами
- Работа с соединениями
- Постоянные соединения с базами данных
- Использование PHP в командной строке
- Сборка мусора
- Динамическая трассировка DTrace
- Copyright © 2001-2023 The PHP Group
- My PHP.net
- Contact
- Other PHP.net sites
- Privacy policy
PHPTv

A Command-Line Remote control for Sony Bravia Android TV written in PHP.
It was one of those evenings where I could not find the fu****g remote for my TV. So instead of doing the work I’m supposed to do. I decided to procrastinate by writing this little program that allows you to control your Sony Android TV over the command line.
# Installation
If you are using composer you can make use of global packages.
$ composer global require mario-deluna/phptvMake sure that you have exported the vendors bin path:
$ export PATH="$PATH:$HOME/.composer/vendor/bin"You can also just download and use the prebuild .phar .
$ wget https://github.com/mario-deluna/PHPTv/releases/download/v1.0.0/phptv.pharAnd if you trust me, add it to your bin dir.
$ sudo chmod a+x phptv.phar $ sudo mv phptv.phar /usr/local/bin/phptv# Setting up the Pre-Shared Key (PSK)
- Go To «Settings» > «Network» > «Home network setup» > «IP control»
- Set «Authentication» to «Normal and Pre-Shared Key»
- Choose a «Pre-Shared Key». (Default is 0000)
Now you should be ready to use the remote.
# Usage
To start the remote just enter phptv .
$ phptv 192.168.1.42 0000Remote key controls:
------------------------------------------------------------ | key | action | description | ============================================================ | ← | Left | Navigate left | ------------------------------------------------------------ | → | Right | Navigate Right | ------------------------------------------------------------ | ↑ | Up | Navigate Up | ------------------------------------------------------------ | ↓ | Down | Navigate Down | ------------------------------------------------------------ | ↵ | Confirm | Enter / Confirm | ------------------------------------------------------------ | ⌫ | Return | Go Back / Return | ------------------------------------------------------------ | c | Command | Opens the command prompt. | ------------------------------------------------------------ | f | Forward | Enter the forward raw commands mode. | ------------------------------------------------------------ | g | Home | Go Home. | ------------------------------------------------------------ | p | TogglePower | Turns the TV on / Off | ------------------------------------------------------------ | m | Mute | Mute / Unmute the Tv. | ------------------------------------------------------------ | b | VolumeDown | Turn down for what? | ------------------------------------------------------------ | n | VolumeUp | Turn up the Volume | ------------------------------------------------------------# PS
This is an absolute «just for fun» and «because I can» project. You will be off much faster just using the normal Remote. I still hope you like this little goof.
# Credits
- Mario Döring
- All Contributors
# License
The MIT License (MIT). Please see License File for more information.
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Remote Control PHP Package
- evently
- Topic Author —>
- Offline
- Official LimeSurvey Partner
- Posts: 10
- Thank you received: 7
4 years 8 months ago #181015 by evently
Remote Control PHP Package was created by eventlyas I use the LimeSurvey remote control for much of my interaction with Limesurvey, I created a PHP package to make it easier to interact with it the remote.
I just pushed v1.0.1, and it currently supports all the Limesurvey Remote options. You can create a new limeremote out of the box, or you can use traits to add functionality to any of your classes.
Hope this helps in developing for Limesurvey, pull requests are welcome, especially with tests.
See all the options and how to install with composer and how to use here:
ps if this is the wrong section, feel free to move!
Best regards,
Stefan (stefan(at)evently.nl)
Evently
Looking for beta testers: interested in connecting Zapier to Limesurvey or
creating Telegram and Messenger bots from Limesurvey? Email me!Configure remote PHP interpreters
The term remote PHP interpreter denotes a PHP engine installed on a remote host or in a virtual environment. The term remote PHP interpreter is used as the opposite of local PHP interpreters that are installed on your computer, refer to Configuring Local PHP Interpreters.
You can access a remote PHP interpreter through SSH, Docker, Docker Compose, Vagrant, or WSL:
By using SSH , you can access a PHP interpreter through the SSH access to the host where the PHP interpreter is installed.
Before you start:
- Configure access to an ssh server on the target remote host and make sure this server is running.
- Make sure the PHP Remote Interpreter and FTP/SFTP/WebDAV Connectivity plugins are enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Installed tab of the Plugins page as described in Install plugins.
- Create an SSH configuration as described in Create SSH configurations.
Configure a PHP interpreter using SSH

- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote. from the popup menu.
- In the Configure Remote PHP Interpreter dialog that opens, choose the SSH method.
- From the SSH configuration list, choose one of the created SSH configurations, or click and create a new configuration as described in Create SSH configurations. To use an interpreter configuration, you need path mappings that set correspondence between the project folders, the folders on the server to copy project files to, and the URL addresses to access the copied data on the server. PhpStorm first attempts to retrieve path mappings itself by processing all the available application-level configurations. If PhpStorm finds the configurations with the same host as the one specified in the selected SSH configuration, the mappings from these configurations are merged automatically. If no configurations with this host are found, PhpStorm displays an error message informing you that path mappings are not configured. To fix the problem, open the PHP page of the IDE settings Control+Alt+S , click in the Path mappings field and map local folders to the folders on the server.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
- For remote hosts, PhpStorm by default suggests the /usr/bin/php location.
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK , PhpStorm checks whether the PHP executable is actually stored in the specified folder.
- If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
- If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
By using the Docker configuration, you can access a PHP interpreter installed in a Docker container.
Before you start:
- Make sure that Docker is downloaded, installed, and configured on your computer as described in Docker.
- Make sure the Docker and PHP Docker plugins are installed and enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Installed tab of the Plugins page as described in Install plugins.
- Configure the PHP development environment in the Docker container to be used.
Learn more about using Docker with PhpStorm in Docker.
Configure a PHP interpreter in a Docker container

- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote. from the popup menu.
- In the Configure Remote PHP Interpreter dialog that opens, choose the Docker method.
- Provide the connection parameters:
- In the Server field, specify the Docker configuration to use. For more information, refer to Configure the Docker daemon connection settings. Select a configuration from the list or click New. and create a new configuration on the Docker page that opens.
- In the Image name field, specify the base Docker image to use. Choose one of the previously downloaded or your custom images from the list or type the image name manually, for example, php:latest or php:7.0-cli . When you later launch the run configuration, Docker will search for the specified image on your machine. If the search fails, the image will be downloaded from the Docker Official Images repository on the Docker Registry page.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
- For Docker containers, PhpStorm by default suggests the php location.
When you click OK , PhpStorm checks whether the PHP executable is actually stored in the specified folder.
- If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
- If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
By using the Docker Compose configuration, you can access a PHP interpreter running in a multi-container Docker Compose environment.
This functionality requires docker-compose version 1.18.0 or later.
Before you start:
- Make sure that Docker is downloaded, installed, and configured on your computer as described in Docker.
- Make sure the Docker and PHP Docker plugins are installed and enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Installed tab of the Plugins page as described in Install plugins.
- Configure the PHP development environment in the Docker container to be used.
Learn more about using Docker Compose with PhpStorm in Using Docker Compose.
Configure a PHP interpreter using Docker Compose

- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote. from the popup menu.
- In the Configure Remote PHP Interpreter dialog that opens, choose the Docker Compose method.
- Provide the connection parameters:
- In the Server field, specify the Docker configuration to use. For more information, refer to Configure the Docker daemon connection settings. Select a configuration from the list or click New. and create a new configuration on the Docker page that opens.
- In the Configuration file(s) field, specify the docker-compose configuration files to use. The base configuration file located in the project root is selected by default. To select a different file or several files, click and select the desired configuration file in the Docker Compose Configuration Files dialog that opens.
- From the Service list, choose the service corresponding to the container the PHP development environment is set up in.
- If necessary, in the Environment Variables field, provide the environment variables. For more information, refer to Docker Compose run configuration settings.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
- For Docker containers, PhpStorm by default suggests the php location.
When you click OK , PhpStorm checks whether the PHP executable is actually stored in the specified folder.
- If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
- If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
- Always start a new container (‘docker-compose run’) : choose this option to have the container started via the run command. The container will be restarted upon each run.
- Connect to existing container (‘docker-compose exec’) : choose this option to have the container started once, and then connect to it via the exec command.
By using the Vagrant configuration, you can access a PHP interpreter installed on the corresponding Vagrant instance.
Before you start:
- Make sure that Vagrant and Oracle’s VirtualBox are downloaded, installed, and configured on your computer as described in Vagrant: Working with Reproducible Development Environments.
- Make sure the Vagrant bundled plugin is enabled in the Installed tab of the Settings | Plugins page as described in Install plugins.
- Make sure that the parent folders of the following executable files are added to the system PATH variable:
- vagrant.bat or vagrant from your Vagrant installation. This should be done automatically by the Vagrant installer.
- VBoxManage.exe or VBoxManage from your Oracle’s VirtualBox installation.
- Configure the PHP development environment in the Vagrant instance to be used.
Configure a PHP interpreter in a Vagrant instance

- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote. from the popup menu.
- In the Configure Remote PHP Interpreter dialog that opens, choose the Vagrant method.
- Provide the connection parameters:
- Specify the Vagrant instance folder which points at the environment you are going to use. Technically, it is the folder where the VagrantFile configuration file for the desired environment is located. Based on this setting, PhpStorm detects the Vagrant host and shows it as a link in the Vagrant Host URL read-only field. To use an interpreter configuration, you need path mappings that set correspondence between the project folders, the folders on the server to copy project files to, and the URL addresses to access the copied data on the server. PhpStorm evaluates path mappings from the VagrantFile configuration file.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
- For Vagrant instances, PhpStorm by default suggests the /usr/bin/php location.
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK , PhpStorm checks whether the PHP executable is actually stored in the specified folder.
- If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
- If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
By using WSL , you can access a PHP interpreter installed in a Linux environment through the Windows Subsystem for Linux compatibility layer.
Before you start, make sure the following prerequisites are met:
- On your Windows 10 machine, make sure the WSL feature is enabled, and the preferred Linux distribution is installed. For more information, refer to the Windows Subsystem for Linux Installation Guide for Windows 10.
- Inside the Linux installation, make sure PHP is installed. For the detailed installation instructions, refer to Debian GNU/Linux installation notes. If you are using Ubuntu, you can run this command in the Terminal to quickly install PHP:
sudo apt install php php-mbstring php-xml php-zip php-curl php-xdebug
Configure a PHP interpreter using WSL

- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote. from the popup menu.
- In the Configure Remote PHP Interpreter dialog that opens, choose the WSL method.
- From the Linux distribution list, choose one of the installed Linux distributions to use.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
- For WSL, PhpStorm by default suggests /usr/local/bin/php .
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK , PhpStorm checks whether the PHP executable is actually stored in the specified folder.
- If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
- If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
Provide additional configuration options
- Press Control+Alt+S to open the IDE settings and then select PHP .
- On the PHP page that opens, click next to the CLI Interpreter list.
- Optionally, customize the configuration settings of the PHP installation in the Additional area of the CLI Interpreters dialog.
- Debugger extension : specify the path to the Xdebug executable file for debugging in On-Demand Mode. This way, PhpStorm can activate Xdebug even if it has been disabled in the php.ini file.
- Configuration options : compose a string of configuration directives to be passed through the -d command line option and thus add new entries to the php.ini file. The directives specified in this field override the default directives generated by PhpStorm, such as:
-dxdebug.mode=debug, -dxdebug.client_host=127.0.0.1, -dxdebug.client_port=9003, -dxdebug.start_upon_error=default
For example, if you specify the -dxdebug.start_upon_error=yes directive, it will override the default -dxdebug.start_upon_error=default directive and thus switch Xdebug to the Just-In-Time (JIT) mode. For more information, refer to Debug in the Just-In-Time mode.
-dxdebug.remote_enable=1, -dxdebug.remote_host=127.0.0.1, -dxdebug.remote_port=9000, -dxdebug.remote_mode=req
For example, if you specify the -dxdebug.remote_mode=jit directive, it will override the default -dxdebug.remote_mode=req directive and thus switch Xdebug to the Just-In-Time (JIT) mode. For more information, refer to Debug in the Just-In-Time mode.
- To add a new entry, click . In the new line, that is added to the list, specify the name of the new entry and its value in the Name and Value fields respectively. You can add as many entries as you need, just keep in mind that they will be transformed into a command line with its length limited to 256 characters.
- To delete an entry, select it in the list and click .
- To change the order of entries, click or .
Upon clicking OK , you return to the CLI Interpreters dialog, where the entries are transformed into a command line.
Configure custom mappings
If you use an interpreter accessible through SSH connection or located on a Vagrant instance or in a Docker container, the mappings are automatically retrieved from the corresponding deployment configuration, Vagrantfile , or Dockerfile .
- Press Control+Alt+S to open the IDE settings and then select PHP .
- From the Interpreter list, choose the remote interpreter for which you want to customize the mappings. The Path Mappings read-only field shows the path mappings retrieved from the corresponding deployment configuration, Vagrantfile , or Dockerfile . To specify the custom mappings, click next to the Path Mappings field.
- The Edit Project Path Mappings dialog shows the path mappings retrieved from the deployment configuration, Vagrantfile , or Dockerfile . These mappings are read-only.
- To add a custom mapping, click and specify the path in the project and the corresponding path on the remote runtime environment in the Local Path and Remote Path fields respectively. Type the paths manually or click and select the relevant files or folders in the dialog that opens.
- To remove a custom mapping, select it in the list and click .
Switch between configured PHP interpreters on the fly
- Press Control+Shift+A and start typing Change PHP interpreter . In the suggestions list, select the Change PHP interpreter action. If necessary, you can assign a keyboard shortcut for this action either directly in the suggestions list by pressing Alt+Enter , or at a later point as described in Keyboard shortcuts.
- In the popup menu that opens, select one of the configured local or remote PHP interpreters.
The selected interpreter will be set as the default project interpreter on the PHP page of the Settings dialog ( Control+Alt+S ). This will also affect configurations that use the default project interpreter (test frameworks’, quality tools’, and run/debug configurations) and commands run in the PhpStorm terminal.
