Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1
    Member
    Join Date
    Jun 2009
    Location
    Kabul
    Posts
    1

    PHP in lightstreamer

    YaHoo
    In the internet I can't find an example of PHP application in lightstreamer hence I write it. Just save as in the file and type "php filename.php".

    PHP Code:
    <?
    $server    = '127.0.0.1';
    $syncPort  = 7001;
    $asyncPort = 7002;

    $control = fsockopen($server, $syncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");
    $feed    = fsockopen($server, $asyncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");

    $greeting = fscanf($control, "%s\n");
    $sid      = explode('|', $greeting[0]);
    $sid      = $sid[0];

    fwrite($control, $sid."|SUB|V\n");
    $cnt = 0;
    while (true) {
        $qry = "0|UD3|S|greetings|S|".$sid."|B|0|S|message|S|Do you count the following?|S|timestamp|S|Count: ".$cnt."\n";
        fwrite($feed, $qry);
        $cnt++;
        sleep(2);
    }

    fclose($feed);
    fclose($control);
    ?>

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan, Italy
    Posts
    521

    Mali,

    Thanks for your contribution!

    Cheers,

    Alessandro

  3. #3
    Member
    Join Date
    Jul 2009
    Location
    sanhe
    Posts
    1

    thank you

    thank you for your share!

  4. #4
    Member
    Join Date
    Jul 2010
    Location
    Jember
    Posts
    1
    How to use this?

  5. #5
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,093
    It is a Remote Data Adapter that requires the same configuration as described in the tutorial for custom Remote Data Adapters and can be launched in place of the two telnet consoles used there.

    The same client as described in the tutorial can be used to get data through this Adapter.

  6. #6
    Member
    Join Date
    Nov 2010
    Location
    Bad Feilnbach
    Posts
    5
    and can be launched in place of the two telnet consoles used there
    Do I understand it right that I have to save this PHP code into a file on my local webserver under the document root. Thereafter I call this file via webbrowser to run it and then this file sends out the messages as long it runs?

    Thanks for your help.

  7. #7
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    Hi,

    the file is intended to be launched from a command line as
    Code:
    php filename.php

    you can certainly try to run it as a page but
    1. you may have problems due to the php.ini configurations (not sure about this, it's some time since I had to work with php)
    2. the file contains a while(true) but the php runtime has a limit in the execution time, after that the execution will be stopped
    HTH

  8. #8
    Power Member
    Join Date
    Sep 2013
    Location
    Coimbatore
    Posts
    121

    I'm getting error my this code

    Quote Originally Posted by malir View Post
    YaHoo
    In the internet I can't find an example of PHP application in lightstreamer hence I write it. Just save as in the file and type "php filename.php".

    PHP Code:
    <?
    $server    = '127.0.0.1';
    $syncPort  = 7001;
    $asyncPort = 7002;

    $control = fsockopen($server, $syncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");
    $feed    = fsockopen($server, $asyncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");

    $greeting = fscanf($control, "%s\n");
    $sid      = explode('|', $greeting[0]);
    $sid      = $sid[0];

    fwrite($control, $sid."|SUB|V\n");
    $cnt = 0;
    while (true) {
        $qry = "0|UD3|S|greetings|S|".$sid."|B|0|S|message|S|Do you count the following?|S|timestamp|S|Count: ".$cnt."\n";
        fwrite($feed, $qry);
        $cnt++;
        sleep(2);
    }

    fclose($feed);
    fclose($control);
    ?>


    I used this code and i'm getting following error, Please help me what is my mistake and how to use this
    Notice: fwrite(): send of 88 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\wamp\www\lightsample\index.php on line 17

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\lightsample\index.php on line 20

  9. #9
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    718
    Hi Vinoth Kumar,

    I need to clarify the scenario of your tests.

    Please note that the piece of code attached is concerning a Remote Data Adapter that connects to the Lightstreamer Proxy Adapter in order to push updates such as in our .NET HelloWorld example (simplified and converted in PHP). So this is on the server side and is out of the context of the Web Server.

    The error you report appears to be related, at least so it seems to us, to the Web Server wamp who complains that your PHP page executes a too long script (more than 30 secs). I confirm you that the code attached does not apply to the client-end but a page similar to this one should be used to get data through this Adapter.

    Hope that helps.

  10. #10
    Power Member
    Join Date
    Sep 2013
    Location
    Coimbatore
    Posts
    121

    Creating Data Adapter using PHP

    I used this code within the lightstreamer/adapters/HelloWorld/classes
    (I'm running lighrstreamer in 8880 port)

    //HelloWorldDataAdapter.php
    <?
    $server = '127.0.0.1';
    $syncPort = 7001;
    $asyncPort = 7002;


    $control = fsockopen($server, $syncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");
    $feed = fsockopen($server, $asyncPort, $errno, $errstr, 5) or die($errno." : ".$errstr."\n");


    $greeting = fscanf($control, "%s\n");
    $sid = explode('|', $greeting[0]);
    $sid = $sid[0];


    fwrite($control, $sid."|SUB|V\n");
    $cnt = 0;
    while (true) {
    $qry = "0|UD3|S|greetings|S|".$sid."|B|0|S|message|S| Do you count the following?|S|timestamp|S|Count: ".$cnt."\n";
    fwrite($feed, $qry);
    $cnt++;
    sleep(2);
    }


    fclose($feed);
    fclose($control);
    ?>

    and added the client file as
    <!DOCTYPE html>
    <html>
    <head>
    <title>Hello World with Lightstreamer</title>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/1.0.7/require.min.js"></script>
    <script src="lightstreamer.js"></script>
    </head>


    <body>
    <div data-source="lightstreamer" data-grid="hellogrid" data-item="greetings" data-field="message">loading...</div>
    <div data-source="lightstreamer" data-grid="hellogrid" data-item="greetings" data-field="timestamp">loading...</div>
    <div data-source="lightstreamer" data-grid="hellogrid" data-item="greetings" data-field="samplename">loading...</div>


    <script>
    require(["LightstreamerClient","Subscription","StaticGr id"],function(LightstreamerClient,Subscription,StaticG rid) {
    var client = new LightstreamerClient("http://localhost:8880/","HELLOWORLD");
    client.connect();

    var grid = new StaticGrid("hellogrid",true);

    var subscription = new Subscription("MERGE",grid.extractItemList(),grid.e xtractFieldList());
    subscription.addListener(grid);
    subscription.setDataAdapter("helloworld");

    client.subscribe(subscription);
    });
    </script>
    </body>
    </html>


    and added the adapter xml file as(lightstreamer/adapters/HelloWorld/adapters.xml)

    <?xml version="1.0"?>
    <adapters_conf id="HELLOWORLD">
    <metadata_provider>
    <adapter_class>com.lightstreamer.adapters.metadata .LiteralBasedProvider</adapter_class>
    </metadata_provider>
    <data_provider name="helloworld">
    <adapter_class>HelloWorldDataAdapter</adapter_class>
    </data_provider>

    </adapters_conf>


    I created the client and server file as mentioned above structure. I'm also having doubt in creating file structure. Whether it is correct or having problem. If it is wrong means please give me an example of file constructing structure.If i used java as an adapter means it's running well.

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 09:36 PM.
Lightstreamer Logo