Jump to content

Error parsing xml data into array


rushman005

Recommended Posts

Yes have downloaded, and installed, please what is the next step to take... Thank you very much sir.. Was waiting for you days now, tho tried somethings with PHP-REDIS but nothing is coming out

I forgot to tell you that, the redis i first downloaded is not based on window, so the one downloaded loads command prompt for both the server and client.. I don't have an installer , you can send the link to me if you see please
Link to comment
Share on other sites

  • Replies 68
  • Created
  • Last Reply

I don't know what you downloaded but it should have been the .msi for the 3.0.504 release. Then it should be installed as a service - you won't be using any command prompts.

Then get the phpredis extension DLL from the PECL repository, stick it in PHP's ext/ directory, and add a

extension=(name of the DLL file)
to your php.ini. Restart and check with phpinfo() that you have the redis extension available.

 

Here's some test code to make sure you have everything set up.

$redis = new Redis();
$redis->connect("127.0.0.1");
$redis->rPush("test", "123");
var_dump($redis->lPop("test")); // 123
Link to comment
Share on other sites

I don't know what you downloaded but it should have been the .msi for the 3.0.504 release. Then it should be installed as a service - you won't be using any command prompts.

Then get the phpredis extension DLL from the PECL repository, stick it in PHP's ext/ directory, and add a

extension=(name of the DLL file)
to your php.ini. Restart and check with phpinfo() that you have the redis extension available.

 

Here's some test code to make sure you have everything set up.

$redis = new Redis();
$redis->connect("127.0.0.1");
$redis->rPush("test", "123");
var_dump($redis->lPop("test")); // 123

 

Hello! HAve tried to install the php-redis extension severally and i kept having this error that C:\xampp\php\ext\php-redis.dll is either not designed to run on windows or it contains an error. the same thing with the .msi file i downloaded that the application is not supported by the platform. And i have .NET framework 4.5 installed already

Thank you

Link to comment
Share on other sites

Do you know the difference between 32 and 64 bit? Do you know that 64-bit applications cannot be run on a 32-bit machine?

 

There's a 32-bit version here.

I have installed the redis 2.4.6.1 but the php-redis.dll extension is still not working. The class is not detected when i run the code above,

i'm still trying to find out why it's like that or do you know what could be wrong.. The same story of C:\xampp\php\ext\php-redis.dll is either not designed to run on windows or it contains an error.

And i have it embedded in the php.ini file already

Thank you

Link to comment
Share on other sites

Did you get the x86 DLL? Did you add the extension= to your php.ini? Did you restart XAMPP? Are there any errors in the log?

 

Meanwhile how are you supposed to use that .NET SDK? I'm not sure how it gets around the concurrency and waiting problem, though I know it would be easier in IIS due to how the server works.

 

I'm trying to help but it feels like I'm holding your hand through all this and it's getting rather tiring.

Link to comment
Share on other sites

Did you get the x86 DLL? Did you add the extension= to your php.ini? Did you restart XAMPP? Are there any errors in the log?

 

Meanwhile how are you supposed to use that .NET SDK? I'm not sure how it gets around the concurrency and waiting problem, though I know it would be easier in IIS due to how the server works.

 

I'm trying to help but it feels like I'm holding your hand through all this and it's getting rather tiring.

I have done everything you mentioned above, i know you want me to learn and i'm been trying hard to do stuffs even before you mention it too, so that we can have good workflow

Mean while , i just want to let know i have .NET framework installed before hand in case you might want to suggest i install it. These are basic things which i wouldn't want to stress you over too. I guess i'm missing a piece somewhere and have been trying

to play around it with google too. May be you should give me little time, i will figure it out install, then i will contact you for the next step

Thank you

Link to comment
Share on other sites

I don't know what you downloaded but it should have been the .msi for the 3.0.504 release. Then it should be installed as a service - you won't be using any command prompts.

Then get the phpredis extension DLL from the PECL repository, stick it in PHP's ext/ directory, and add a

extension=(name of the DLL file)
to your php.ini. Restart and check with phpinfo() that you have the redis extension available.

 

Here's some test code to make sure you have everything set up.

$redis = new Redis();
$redis->connect("127.0.0.1");
$redis->rPush("test", "123");
var_dump($redis->lPop("test")); // 123

 

Hi requinix

Thank you very much for all the support you have been providing me on this project.

 

I detected a lots of program is affecting the redis coupled with the fact that i didn't get the right program.

SO had to reload my PC and all other necessary application. I have my redis up and running tested with the code and i was able to echo out string(3) "123" on my browser

So please what step are we taking next??

 

Then about the .NET SDK. It is just to use their dll which has done majority of stuffs like scanning for device, connecting , exchanging XML infromation.

This will limit our job to collecting alarm information and displaying the camera video feed for operator to see what is going on when there is Alarm.

 

Thanks

Link to comment
Share on other sites

I detected a lots of program is affecting the redis coupled with the fact that i didn't get the right program.

SO had to reload my PC and all other necessary application. I have my redis up and running tested with the code and i was able to echo out string(3) "123" on my browser

So please what step are we taking next??

Redis has "lists", which are really exactly what they sound like. We can use a list to pass information back and forth between the one script that waits for the device to report and another script which will wait for those reports to come in. The main advantage is that the second script can be blocking, meaning it can sit and wait until a report happens.

 

There's a few parts to this process:

 

1. The main script waits on the device. It handles any XML it receives and does stuff in Redis.

2. The AJAX script connects to Redis and gets data if available, or waits until there is data, or waits until it times out without data.

3. A Redis list to track events that happen. It only ever has one element - there is no need for the AJAX to know of events historically, just to get them as they happen.

4. A Redis key/value pair (ie, using Redis as a cache) containing the most recent event. The list tells what value to get, and the key/value can expire after a period of time when it is too old to be of value.

 

This process only works if there is one AJAX script. If you ever want more than one, like two browser clients on different machines, then this process will not work. If you think this might possibly happen then it will be easier to change things now than later.

 

The overall structure to the code goes like

// main script

connect to redis

when xml is received from apu {
	skip handshake xml

	optional xml processing
	optionally record the event somewhere for actual historical records

	clear redis list

	create random string for use as redis key
	in redis set key = whatever information you want the ajax to receive, with a reasonable expiration

	push random string into redis list
}
// ajax script

connect to redis

blocking pop item from redis list
if pop timed out then return nothing

get value from redis using popped item as cache key
if no value then return nothing // too old

optional processing of the item
return whatever the ajax script needs to return
Does that process make sense? Any questions before we try the code?

 

Then about the .NET SDK. It is just to use their dll which has done majority of stuffs like scanning for device, connecting , exchanging XML infromation.

This will limit our job to collecting alarm information and displaying the camera video feed for operator to see what is going on when there is Alarm.

But how are you supposed to use it? What classes and objects? How does it connect? How does it report intrusion events?
Link to comment
Share on other sites

Redis has "lists", which are really exactly what they sound like. We can use a list to pass information back and forth between the one script that waits for the device to report and another script which will wait for those reports to come in. The main advantage is that the second script can be blocking, meaning it can sit and wait until a report happens.

 

There's a few parts to this process:

 

1. The main script waits on the device. It handles any XML it receives and does stuff in Redis.

2. The AJAX script connects to Redis and gets data if available, or waits until there is data, or waits until it times out without data.

3. A Redis list to track events that happen. It only ever has one element - there is no need for the AJAX to know of events historically, just to get them as they happen.

4. A Redis key/value pair (ie, using Redis as a cache) containing the most recent event. The list tells what value to get, and the key/value can expire after a period of time when it is too old to be of value.

 

This process only works if there is one AJAX script. If you ever want more than one, like two browser clients on different machines, then this process will not work. If you think this might possibly happen then it will be easier to change things now than later.

First of all i'm very sorry for replying late, was trying to get your reply but it did not come on time.

I have another integration i will do where there will be two of the device connected in series, which i will collect the information later.

 

 

The overall structure to the code goes like

// main script

connect to redis

when xml is received from apu {
	skip handshake xml

	optional xml processing
	optionally record the event somewhere for actual historical records

	clear redis list

	create random string for use as redis key
	in redis set key = whatever information you want the ajax to receive, with a reasonable expiration

	push random string into redis list
}
// ajax script

connect to redis

blocking pop item from redis list
if pop timed out then return nothing

get value from redis using popped item as cache key
if no value then return nothing // too old

optional processing of the item
return whatever the ajax script needs to return
Does that process make sense? Any questions before we try the code?

 

 

It really make sense. But there is one thing that first code we are using to receive XML

only receive two XML from the device and it will stop after that. Even if i reconnect just two again it will just connect and not sending any information again

 

 

 

But how are you supposed to use it? What classes and objects? How does it connect? How does it report intrusion events?

They have class in the SDK called DevicemodelAPU.cs that all classes that does connection has been created, and also function to receive the alarm has been created

we just need to call it and display whatever we want with it

 

Many thanks to you requinix, would not have gone far without you

Appreciate

Link to comment
Share on other sites

First of all i'm very sorry for replying late, was trying to get your reply but it did not come on time.

I have another integration i will do where there will be two of the device connected in series, which i will collect the information later.

 

 

 

 

It really make sense. But there is one thing the code we are using to receive the information from the device only send two XML and it will stop after that. Even if i reconnect just two again it will just connect and not sending any information again

So please i think this is the first thing we need to resolve look at the code again


<?php
function xml_stream_parser($socket, $callback) {
    $depth = 0; // node depth
    $xml = "";  // xml string buffer

    do {
        // initialize parser
        if ($depth == 0) {
            $parser = xml_parser_create();
            // handler tracks xml node depth, builds the buffer, and invokes the callback at the end
            xml_set_default_handler($parser, function($parser, $data) use($callback, &$depth, &$xml) {
                $xml .= $data;
                if ($data[0] == "<" && $data[1] == "/") {
                    $depth--;
                    if ($depth == 0) {
                        $callback($xml);
                    }
                } else if ($data[0] == "<") {
                    $depth++;
                }
            });
        }

        // read until the parser did something
        // xml_parse natively supports a streaming approach
        do {
			$buffer = socket_read($socket, 1024, PHP_NORMAL_READ); //PHP_NORMAL_READ
        } while ($buffer != "" && !xml_parse($parser, $buffer));

        if ($buffer === false) {
            trigger_error("Socket error: " . socket_strerror(socket_last_error($socket)), E_USER_WARNING);
        }

        // close the parser at the end of the document (can't reuse for another one)
        if ($depth == 0) {
            $xml = "";
            xml_parser_free($parser);
            unset($parser);
        }
    } while ($buffer != "");
}

set_time_limit(0);
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($s, "192.168.0.78", 10001);
socket_set_nonblock($s); // block until data
socket_set_option($s, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 5, "usec" => 0]); // timeout after 5 seconds
xml_stream_parser($s, function($xml) { // receives a complete xml document
   file_put_contents("intrusion.xml", $xml);
   //echo ($xml);  deal with $xml
});
socket_shutdown($s);
socket_close($s);
?>

 

 

 

They have class in the SDK called DevicemodelAPU.cs that all classes that does connection has been created, and also function to receive the alarm has been created

we just need to call it and display whatever we want with it

 

Many thanks to you requinix, would not have gone far without you

Appreciate

 

Link to comment
Share on other sites

But there is one thing that first code we are using to receive XML

only receive two XML from the device and it will stop after that. Even if i reconnect just two again it will just connect and not sending any information again

Last I knew that was after we made the changes to the code so it only received two XML documents... The script ends but the next time it tries to run it won't be able to connect. So we don't make it end.

 

Or are you saying the original version of that one function I wrote, without the limiting, stopped after two as well?

Link to comment
Share on other sites

Last I knew that was after we made the changes to the code so it only received two XML documents... The script ends but the next time it tries to run it won't be able to connect. So we don't make it end.

 

Or are you saying the original version of that one function I wrote, without the limiting, stopped after two as we

 

 

Yes and as well it will not connect even if all seem to be working fine with ping and telnet , it will still receive connection not to talk of receiving information

Link to comment
Share on other sites

Okay, so after going through the SDK you provided me, it seems their architecture is more complicated than just a simple socket. Replicating the necessary procedures in PHP could be a pain, and in fact I can't do it yet because the code that does it is in a different DLL file (FSIUtilitiesLibrary).

 

So let's try the .NET approach. Are the DLLs installed on the system? If not, put a copy of them - all of them that you have - with your web server's binary. Then go into your php.ini and make sure the php_com_dotnet.dll extension is enabled; if not then enable and restart.

 

Here's some test code I think should work, but I can't test it.

<?php

header("Content-Type: text/plain");

$factory = new DOTNET("FSI.DeviceSDK", "FSI.DeviceSDK.FiberDefenderDevice.FiberDefenderAPUDeviceFactory") or die("No SDK");
$devices = $factory->ScanForDevices();
print_r($devices);
Link to comment
Share on other sites

Okay, so after going through the SDK you provided me, it seems their architecture is more complicated than just a simple socket. Replicating the necessary procedures in PHP could be a pain, and in fact I can't do it yet because the code that does it is in a different DLL file (FSIUtilitiesLibrary).

 

So let's try the .NET approach. Are the DLLs installed on the system? If not, put a copy of them - all of them that you have - with your web server's binary. Then go into your php.ini and make sure the php_com_dotnet.dll extension is enabled; if not then enable and restart.

 

Here's some test code I think should work, but I can't test it.

<?php

header("Content-Type: text/plain");

$factory = new DOTNET("FSI.DeviceSDK", "FSI.DeviceSDK.FiberDefenderDevice.FiberDefenderAPUDeviceFactory") or die("No SDK");
$devices = $factory->ScanForDevices();
print_r($devices);

Hi requinix,

Many thanks, i did that and copied all my DLL files and paste in ext directory of PHP. Then i search through my php.ini for the extension i didnt see so i included it and restarted my Server. BUt ever since then i have unable to bring up my Simulator to test the code you sent, just keep crashing 

Link to comment
Share on other sites

Hi requinix,

Many thanks, i did that and copied all my DLL files and paste in ext directory of PHP. Then i search through my php.ini for the extension i didnt see so i included it and restarted my Server. BUt ever since then i have unable to bring up my Simulator to test the code you sent, just keep crashing 

<br /><b>Fatal error</b>:  Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified.' in C:\xampp\htdocs\integration\test.php:4Stack trace:#0 C:\xampp\htdocs\integration\test.php(4): dotnet->dotnet('FSI.DeviceSDK', 'FSI.DeviceSDK.F...')#1 {main}  thrown in <b>C:\xampp\htdocs\integration\test.php</b> on line <b>4</b><br />

Thats the error i got 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.