simplexml字符串无法解析为xml cron

时间:2019-07-14 07:02:40

标签: php cron simplexml

我有一个计划,要求将经济中的产品强制进口到供应商。任务之一是从供应商那里获得回复,我对此有疑问。

在error.log中是这个

PHP消息:PHP致命错误:未捕获的异常:无法将字符串解析为XML

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

能帮我吗?我试图更改xml文件的编码,但没有成功。问题仅在于从cron调用脚本时。如果我手动运行它,没有任何问题。谢谢

编辑1:它总是只发生一次卷曲,而不是一次发生

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 个答案:

没有答案