Solr for PHP: getDigestedResponse not working - php

I've managed to install Solr for PHP on my Windows 7 64bit Machine using the plugin I found here:
downloads.php.net/pierre/
It was linked to on this site:
wiki.apache.org/solr/SolPHP
(links are not clickable because I'm a new user)
I've got everything up and running, searches and indexing are working, but only when I use the getRawResponse() Method and parse it through SimpleXml (http://de.php.net/manual/en/book.simplexml.php).
The getDigestedResponse() method, which ist supposed to return a PHP-Object, just returns string(1) " ".
The method getResponse() (http://docs.php.net/manual/en/solrresponse.getresponse.php) just times out.
It wouldn't be that much of a problem, but some of the XML from the Raw Response doesn't seem to be valid and parsed with simpleXML, some of the attributes are missing, using regular expressions to get the needed data would be too much of a hassle.
Has anyone get this to work yet? Help is greatly appreciated!

Depends on how you are parsing the response. Try code below and drop the PHP/PECL solr libs and go CURL (ex: hostNameHere:8983/solr/select/?q=solr&start=0&rows=10&indent=on and send the result XML to the function below).
If you can access a resource (solr) via a URL, then there is no need to use an ancillary library to do what CURL can do:
function makeSimpleXML($xml) {
$dom = new DOMDocument;
$dom->loadXML($xml);
if (!$dom) {
// ErrorUtility::throwFatal("could not parse xml. please check the format", "XMLParisng Error");
}
return simplexml_import_dom($dom);
}

Related

How to create a XML File From Server Response (PHP)

I have a response that I got from a server using PHP, it is returned in XML format. Unfortunately I cannot disclose the code that is in question since it is for a client, but here is a shortened version of it:
// server request code here…
$result = $soap>__doRequest($xmltosend,URL,$action,1); //the final part of the request process…
// $result is the returned xml that is to be converted into a separate file
Is there any way that I could take the returned XML and make a new file? If you have any questions I will be more than happy to answer them!
Thanks in advance!
Try it with DOMDocument:
$doc = new DOMDocument();
$doc->loadXML($result);
$doc->save("/tmp/your-document.xml");
You can find more on this in the php documentation

How to display Now Playing in my website with Icecast2 and Liquidsoap

I couldn't find any better answer to this online, even the document of liquidsoap isn't helpful. What I want to happen is to grab the current song title and artist being played in my streaming server(icecast). I found in some forum that they were able to do it but they didn't explain it how, here's the liquidsoap script that they used:
def apply_metadata(m) =
title = m["title"]
artist = m["artist"]
album = m["album"]
[("artist","#{artist}"),("title","#{album} - #{title}")]
end
centovacast.callback_autodj := fun(s) -> map_metadata(apply_metadata,s)
This script i believe is also for centova and autodj only. While I do not use those technology (I'm using Ubuntu 16.04, Icecast2, Liquisoap, PHP, HTML5/CSS),
is this possible to do using the tools I'm currently using?
I used to use websockets to get the metadata but I found it frustrating that it was always out of sync.
The only way to solve it is to have the metadata encoded into the stream so you receive it at the same time as the audio.
I did a bit of digging around to find out how the icecast servers do it and put together a service worker script which adds the necessary header to your request to obtain a stream including metadata and then extracts it for you.
The code is here and there is a simple demo here
I hope this helps, anyway, I think that here, weserWEB, has already somehow said something similar.
If you're using Icecast version 2.4.4 you can consume the metadata from this endpoint: (if not, consider downloading that version)
http://<your-ipaddress-or-domain>:<port_number>/status-json.xsl
Just put that in any browser and you will get a JSON with the name of the song and title you are streaming, you have to configure properly your streaming client first, of course.
Then you can get the metadata from that endpoint without problems in your PHP. You can use CURL to get the JSON data, liquidsoap not necessary.
I'm not sure why you are dragging the source client into this.
A proper stream sent to an Icecast mountpoint will have metadata for currently playing audio.
This has been pointed out elsewhere. Icecast since 2.4.1 provides a proper JSON metadata export.
Querying JSON from within a website is very much a solved problem and considered an exercise for the inclined reader.
Why don't you grab this at icecast directly?
PHP:
function get_icecast_info($server_ip, $server_port, $admin_user, $admin_password) {
$index = #file_get_contents("http://".$admin_user.":".$admin_password."#".$server_ip.":".$server_port."/admin/stats.xml");
if($index) {
$xml = new DOMDocument(); if(!$xml->loadXML($index)) return false; $arr = array(); $listItem = $xml->getElementsByTagName("source");
foreach($listItem as $element) {
if($element->childNodes->length) {
foreach($element->childNodes as $i){ $arr[$element->getAttribute("mount")][$i->nodeName] = $i->nodeValue; }
}
}
return $arr;
} return false;
}
And this is the output (array):
$arr = get_icecast_info($ice_host, $ice_aport, $ice_user, $ice_pass);

php simple_load_string always returning zero data on well formed xml docs

I have been trying to load a number of XML files into a PHP page using a simple load string. Strange as this might sound, not one loads, and all return as empty.
I can load them using $xmldoc = new DomDocument( '1.0' ); and I can view all directly in the browser. I'm getting really frustrated because I can't see why they should fail to load.
I am using offline development - Win7 proff, XAMPP Version: 1.8.1 with PHP 5.4 loaded.
Example of my simple loading code:
$xml = simplexml_load_string('menu45.xml');
if ( !$xml ) {
echo "empty!!!!";
// return 'Error';
}
I am hoping someone will let me know if there is a problem with using a simple load string on a Windows machine or if there's a bug in PHP 5.4, or XAMPP has issues with it, or something.
I've Google'd and read everything I could for an 18 hour stint without joy. Any suggestion would be greatly appreciated.
simplexml_load_string() loads strings, not files.... and "menu45.xml" isn't a well formed xml string. Try simplexml_load_file() instead.

SimplePie Getting an invalid XML document

I am using a very cool php library(whatever it is called) called SimplePie. I am using the latest version.
I have this code:
$url = 'http://www.seobook.com/feeds.shtml';
$SimplePieFeed->set_feed_url($url);
$SimplePieFeed->force_feed(true);
$SimplePieFeed->enable_order_by_date(true);
$success = $SimplePieFeed->init();
if( !$SimplePieFeed->error() ) {
foreach( $SimplePieFeed->get_items() as $item ) {
......
}
} else {
print_r( $SimplePieFeed->error() );
}
Why is it that when I run this code I'm getting this kind of error:
This XML document is invalid, likely due to invalid characters. XML error: not well-formed (invalid token) at line 8, column 76
I try to run this one on Simplepie's demo and everything is going well. Why is it that when I run it on my end i'm having that kind of error? Is it because of a cache? I noticed that Simplepie is storing feeds in a cache. I have tried $SimplePieFeed->enable_cache(false); but still i'm getting that error. I'm not even sure if that's related to that kind of error. LOL!
Your help would be greatly appreciated and rewarded! :Thank you very much!
Simple there is problem in your xml file you should remake the .xml file,if you are using wordpress simple use plugin called google site maps its pretty good.
If you using some thing else like php, or html base site you should make valid xml document maker like some listed here,
xml-sitemaps.com
xmlgrid.net (editor viewer)
web-site-map.com
May it help you little in your case.

How to use an XSD schema in php

I need to use an XSD schema to develop a Web Service that receive reservations from an Hotel. I've the url of the xsd. This is the OTA_HotelResNotifRQ.
I don't know how to begin with this. Someone can help me?
Thanks
The PHP DOM extension, which is available almost all the time can do this natively.
$dom = new DomDocument;
$dom->loadXML($contentOfResponse);
if ($dom->schemaValidate('path/to/schema.xsd')) {
// Valid response from service
} else {
// Invalid response
}
Of course, you can also load the document to validate from a file.
Documentation: http://ca.php.net/manual/en/domdocument.schemavalidate.php

Categories