【发布时间】:2021-11-24 22:13:26
【问题描述】:
这是一个奇怪的问题。
当我尝试通过“启动内置 Web 服务器”调试位于网络驱动器 (Z:\htdocs\index.php) 上的 .php 文件时,服务器启动正常,但是当我尝试在浏览器中打开文件时出现错误:
警告:未知:无法打开流:中没有这样的文件或目录 第0行未知
致命错误:需要打开失败 'Z:\htdocs\index.php' (include_path='E:\Program Files\VSCode\data\php\pear') 在 Unknown on line 0
我的Z:\ 驱动器映射到\\192.168.0.100,所以当我在VSCode 中打开与\\192.168.0.100\htdocs\index.php 相同的文件并尝试调试它时,它工作得很好(因为它是由PHP 执行的)。
电脑上没有安装webserver,VSCode直接执行php.exe。它作为非提升用户而不是服务执行,因此网络访问应该不是问题。事实上,当我使用完全相同的参数启动 php.exe 并执行如下操作时:
echo file_get_contents("Z:\htdocs\index.php");
php 访问和读取文件似乎没有问题。
任何想法为什么 PHP 拒绝网络驱动,但允许服务器路径?
[更新] 我已经尝试将网络驱动器映射到本地计算机,VSCode 调试工作正常。
[更新2]
我发现了问题:我的htdocs 文件夹是服务器上另一个驱动器的 NTFS 连接。服务器和客户端计算机都没有访问它的问题,但是无论出于何种原因 PHP 不喜欢它。任何想法为什么以及如何解决这个问题?
我正在运行可移植的 VSCode v1.60.2 x64、PHP 8.0.2、PHP Xdebug extension v1.19.0
我的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "vscode-edge-devtools.debug",
"request": "launch",
"name": "Launch Microsoft Edge and open the Edge DevTools",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-i",
"-S",
"localhost:8080"
],
"program": "",
"webRoot": "${workspaceFolder}",
"cwd": "${workspaceFolder}",
"port": 9000,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"name": "Launch Microsoft Edge and open the Edge DevTools",
"action": "startDebugging"
}
}
]
}
还有php.ini
[PHP]
engine=On
short_open_tag=Off
precision=14
output_buffering=4096
zlib.output_compression=Off
implicit_flush=Off
unserialize_callback_func=
serialize_precision=-1
disable_functions=
disable_classes=
zend.enable_gc=On
zend.exception_ignore_args=Off
zend.exception_string_param_max_len=15
expose_php=On
max_execution_time=120
max_input_time=60
memory_limit=512M
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors=On
display_startup_errors=On
log_errors=On
log_errors_max_len=1024
ignore_repeated_errors=Off
ignore_repeated_source=Off
report_memleaks=On
variables_order="GPCS"
request_order="GP"
register_argc_argv=Off
auto_globals_jit=On
post_max_size=40M
auto_prepend_file=
auto_append_file=
default_mimetype="text/html"
default_charset="UTF-8"
include_path="E:\Program Files\VSCode\data\php\pear"
doc_root=
user_dir=
extension_dir="E:\Program Files\VSCode\data\php\ext"
enable_dl=Off
file_uploads=On
upload_tmp_dir="E:\Program Files\VSCode\data\php\tmp"
upload_max_filesize=40M
max_file_uploads=20
allow_url_fopen=On
allow_url_include=Off
default_socket_timeout=60
extension=bz2
extension=curl
extension=fileinfo
extension=gettext
extension=mbstring
extension=exif
asp_tags=Off
display_startup_errors=On
track_errors=Off
y2k_compliance=On
allow_call_time_pass_reference=Off
safe_mode=Off
safe_mode_gid=Off
safe_mode_allowed_env_vars=PHP_
safe_mode_protected_env_vars=LD_LIBRARY_PATH
error_log="E:\Program Files\VSCode\data\php\logs\php_error.log"
register_globals=Off
register_long_arrays=Off
magic_quotes_gpc=Off
magic_quotes_runtime=Off
magic_quotes_sybase=Off
[CLI Server]
cli_server.color=On
[Pdo]
pdo_mysql.default_socket="MySQL"
[Pdo_mysql]
pdo_mysql.default_socket=
[ODBC]
odbc.allow_persistent=On
odbc.check_persistent=On
odbc.max_persistent=-1
odbc.max_links=-1
odbc.defaultlrl=4096
odbc.defaultbinmode=1
[bcmath]
bcmath.scale=0
[browscap]
browscap="E:\Program Files\VSCode\data\php\extras\browscap.ini"
[Session]
session.save_handler=files
session.save_path="E:\Program Files\VSCode\data\php\tmp"
session.use_strict_mode=0
session.use_cookies=1
session.use_only_cookies=1
session.name=PHPSESSID
session.auto_start=0
session.cookie_lifetime=0
session.cookie_path=/
session.cookie_domain=
session.cookie_httponly=
session.cookie_samesite=
session.serialize_handler=php
session.gc_probability=1
session.gc_divisor=1000
session.gc_maxlifetime=1440
session.referer_check=
session.cache_limiter=nocache
session.cache_expire=180
session.use_trans_sid=0
session.sid_length=26
session.trans_sid_tags="a=href,area=href,frame=src,form="
session.sid_bits_per_character=5
[Assertion]
zend.assertions=1
[Tidy]
tidy.clean_output=Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="./tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit=5
[ldap]
ldap.max_links=-1
[Syslog]
define_syslog_variables=Off
[Session]
define_syslog_variables=Off
[Date]
date.timezone=America/New_York
[Sybase-CT]
sybct.allow_persistent=On
sybct.max_persistent=-1
sybct.max_links=-1
sybct.min_server_severity=10
sybct.min_client_severity=10
[XDebug]
zend_extension = "xdebug-3.0.4-8.0-vs16-x86_64"
xdebug.mode = debug, trace, develop
xdebug.start_with_request = yes
xdebug.trace_output_dir = "E:\Program Files\VSCode\data\php\tmp"
【问题讨论】:
-
映射的驱动器只能由创建它的用户访问,也许VSCode以不同的用户运行PHP?
-
@emptyhua,不,系统上只有一个用户。
-
问题似乎是我的
htdocs文件夹是服务器上另一个驱动器的 NTFS 连接。服务器和客户端计算机都没有访问它的问题,但是无论出于何种原因 PHP 不喜欢它。任何想法为什么以及如何解决这个问题?
标签: php visual-studio-code xdebug