dream8877 2019-07-14 07:02
浏览 99

simplexml字符串无法解析为xml cron

I have a cron that makes force import of products from economy sw to a supplier. On of the tasks is to obtain respone from the supplier and I have problem with it.

In the error.log is this

PHP message: PHP Fatal error: Uncaught Exception: String could not be parsed as XML

/var/www/clients/client222/web662/web/src/ImportStore.php(362): SimpleXMLElement->__construct('', NULL, false)

Can you help me please? I tried to change encoding of xml file but without any success. The problem is only when script is called from cron. If I run it manually, there isn't any problem. Thank you

EDIT 1: it always happens only with one curl, not both at a time

private function sendStockData($products, $country) {
    echo $country;
    $latte = new \Latte\Engine();
    $latte->setTempDirectory(__DIR__ . "/requests/import");
    $parameters['products'] = $products;
    $xml = $latte->renderToString(__DIR__ . "/requests/import/importStore-PneuB2B.latte", $parameters);
    $pairedCounterCZ = 0;
    $pairedCounterSK = 0;

    $data = null;
    if ($country === null || $country === "cz") {
        echo "cz";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->config["pneub2b"]["host"] . "?cmd=update");
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
        curl_setopt($ch, CURLOPT_USERPWD, $this->config["pneub2b"]["login"] . ":" . $this->config["pneub2b"]["pass"]);
        $data = curl_exec($ch);
        curl_close($ch);




        file_put_contents(__DIR__ . "/last_data_received-cz.xml", $data);

        $xmlResponse = new \SimpleXMLElement($data, null, false);

        foreach ($xmlResponse->Items->Item as $item) {

            }
        }



    $data = null;
    if ($country === null || $country === "sk") {
        echo "sk";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->config["pneub2b"]["host"] . "?cmd=update");
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
        curl_setopt($ch, CURLOPT_USERPWD, $this->config["pneub2b"]["loginSK"] . ":" . $this->config["pneub2b"]["passSK"]);
        $data = curl_exec($ch);
        curl_close($ch);


        file_put_contents(__DIR__ . "/last_data_received-sk.xml", $data);

        $xmlResponse = new \SimpleXMLElement($data, null, false);

        foreach ($xmlResponse->Items->Item as $item) {
        }
  }

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作