php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76330 XPath only works in a linux server not local windows IIS
Submitted: 2018-05-11 15:13 UTC Modified: 2018-05-12 10:22 UTC
From: kj-8791 at hotmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *XML functions
PHP Version: 7.2.5 OS: windows 10 enterprise
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kj-8791 at hotmail dot com
New email:
PHP Version: OS:

 

 [2018-05-11 15:13 UTC] kj-8791 at hotmail dot com
Description:
------------
problem is only $data is null in a local windows IIS even if i connect a domain to my localhost, so a question is Windows 10 Enterprise lacking something default as PHP stats XPath is integrated and is working in a linux enviroment??

i have PHP 7.2.5 plus Microsoft VC15 runtime

no changes are made to the system files standard installation of PHP

Question? What is needed for this to work in windows?
as Windows Enterprise should have all needed because PHP code works

Test script:
---------------
//Get parsing url for retrieving forex data
$parseurl="https://www.investing.com/technical/technical-summary";
//Create XPath object
$parsedoc=new DOMDocument();@$parsedoc->loadHTMLFile($parseurl);$xpath=new DOMXPath($parsedoc);

$data=$xpath->query('//*[@id="technical_summary_container"]/table/tbody/tr[3]/td[2]')->item(0)->nodeValue."\n";
echo $data;

Expected result:
----------------
$data should have one of this results

Strong Sell
Sell
Neutral
Buy
Strong Buy

Actual result:
--------------
$data is null in a windows 10 Enterprise PHP standard installation, without plugins and external packages

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-11 15:17 UTC] peehaa@php.net
You are using the STFU operator (@) which prevent you from seeing what is going wrong.

Remove it and check the error message.
 [2018-05-11 15:18 UTC] peehaa@php.net
Also make sure the data you get in is what you think it is.
 [2018-05-11 15:31 UTC] kj-8791 at hotmail dot com
Yes i have removed @ and it doesn't show anything, totally empty

when checking the page direct i only see a white page, when i use http request from javascript from another page to retrive "xpath page" is shows undefined, but this is only in a local windows 10 testing enviroment, if i upload to a linux server it works, but it should work locally as i use webserver IP not localhost as i have read that localhost have security limits when retriveng data from another server on internet

i can retrive all other pages so webserver works
 [2018-05-11 15:36 UTC] kj-8791 at hotmail dot com
retrive from
@id="technical_summary_container"]/table/tbody/tr[3]/td[2]

# should show one of this and it does in linux but not in windows #
Strong Sell
Sell
Neutral
Buy
Strong Buy
 [2018-05-11 15:57 UTC] peehaa@php.net
Are you sure $data is actually null or do you get a fatal error?
 [2018-05-11 16:37 UTC] kj-8791 at hotmail dot com
Yes i have tried strlen($data) and shows 0

i have found error settings in php.ini and changed it to "ON" and it shows now errors
Notice: Trying to get property 'nodeValue' of non-object in D:\Server\test\app\signal-eurusd\index.php on line 8

but it works in mzzhost.com and uses linux so it is strange...

for more information i have checked this problem since windows 10 come out and updated both system and php many times to see if this is a windows bug, it is not high level bug as linux works, but it is good if this would be fixed so it works in all systems, i can think that XPath doesn't work at all in windows because some security restrictions but google has no information how to fix that
 [2018-05-11 17:40 UTC] kj-8791 at hotmail dot com
Thanks for help i have solved it as i found solution in
https://stackoverflow.com/questions/22734182/403-error-when-using-file-get-contents

added in index.php
libxml_use_internal_errors(true); shows forbidden so i added
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)'); and it works

but it does not answer why it is working in linux, useragent should be added as default in php.ini

hopefully this workaround helps other people if this is mention somewhere in FAQ
 [2018-05-12 10:22 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-05-12 10:22 UTC] cmb@php.net
> added in index.php
> libxml_use_internal_errors(true); shows forbidden so i added
> ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)'); and it works

So this is not XPath related; actually, it is not even a bug in
PHP.  You always have to properly check the return values for
failures.

> useragent should be added as default in php.ini

No.  Instead you may think about *why* the site responds with 403
Forbidden, if no User-Agent is sent.  Hint: likely the site owners
don't want their site to be scraped by arbitrary bots.
 [2018-05-13 00:11 UTC] a at b dot c dot de
They may also already provide you with what you're wanting already prepackaged.

https://www.investing.com/webmaster-tools/technical-summary
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC