Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php DOMDocument->;处理用户中止后,save()失败_Php_Xml_Libxml2_Php 7 - Fatal编程技术网

Php DOMDocument->;处理用户中止后,save()失败

Php DOMDocument->;处理用户中止后,save()失败,php,xml,libxml2,php-7,Php,Xml,Libxml2,Php 7,在PHP中,可能会调用,但在我的场景中(有时会被忽略)会被明确调用,请参见下文 如果我想在之后调用->saveXML()(->saveXML()工作正常)(例如,从注册的关闭函数或类实例析构函数),则受支持的PHP/libxml与我的注册不符。相关的也是 让这些例子说明: PHP版本: php --version PHP 7.1.4 (cli) (built: Apr 25 2017 09:48:36) ( NTS ) Copyright (c) 1997-2017 The PHP Group

PHP
中,可能会调用,但在我的场景中(有时会被忽略)会被明确调用,请参见下文

如果我想在之后调用
->saveXML()
->saveXML()
工作正常)(例如,从注册的
关闭函数
或类实例
析构函数
),则受支持的PHP/libxml与我的注册不符。相关的也是

让这些例子说明:

PHP版本:

php --version
PHP 7.1.4 (cli) (built: Apr 25 2017 09:48:36) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
要复制用户中止我正在通过python2.7
run.py
运行php:

import subprocess

cmd = ["/usr/bin/php", "./user_aborted.php"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)

# As this process exists here and the user_aborted.php
# has sleeps/blocks in for-cycle thus simulating a user-abort
# for the php subprocess.
php脚本
用户\u被中止。php
尝试在关闭函数中保存XML

<?php

ignore_user_abort(false);
libxml_use_internal_errors(true);

$xml = new DOMDocument();
$xml_track = $xml->createElement( "Track", "Highway Blues" );
$xml->appendChild($xml_track);

function shutdown() {
    global $xml;

    $out_as_str = $xml->saveXML();

    fwrite(STDERR, "\nout_as_str: " . var_export($out_as_str, true) . "\n");

    $out_as_file = $xml->save('out.xml');

    fwrite(STDERR, "\nout_as_file: >" . var_export($out_as_file, true) . "<\n");
    fwrite(STDERR, "\nerrors: \n" . var_export(libxml_get_errors(), true) . "\n");
}

register_shutdown_function('shutdown');

$i = 2;

while ($i > 0) {
    fwrite(STDERR, "\n PID: " . getmypid() . " aborted: " . connection_aborted());
    echo("\nmaking some output on stdout"); // so user_abort will be checked
    sleep(1);
    $i--;
}

很抱歉发了这么长的帖子,但我一整天都在浏览PHP/libxml2代码,没有任何成功之处/

原因:

php --version
PHP 7.1.4 (cli) (built: Apr 25 2017 09:48:36) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
原来这是由于修复了以前的错误

链接:

链接的
php\u libxml\u streams\u IO\u write
函数是
writecallback
(设置)用于
docp
对象的缓冲区,该对象为调用
libxml
而移交。在缓冲区为
NULL
的地方结束,因此为
->save(*)
指定的文件不会被写入

解决方法:

php --version
PHP 7.1.4 (cli) (built: Apr 25 2017 09:48:36) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
使用
->saveXML()
获取字符串形式的XML表示,并使用
文件内容(*)
手动编写:


$xml->save('out.xml')也从类析构函数调用。@andras.tim好的,我已经更新了标题/文本