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]<?
$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);
?>[/PHP]
    a month later
    a year later
    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.
    5 months later

    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.
    Hi,

    the file is intended to be launched from a command line as
    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
    3 years later

    malir 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]<?
    $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);
    ?>[/PHP]





    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.phpon line 17

    Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\lightsample\index.phpon line 20
    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.
    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","StaticGrid"],function(LightstreamerClient,Subscription,StaticGrid) {
    var client = new LightstreamerClient("http://localhost:8880/","HELLOWORLD");
    client.connect();

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

    var subscription = new Subscription("MERGE",grid.extractItemList(),grid.extractFieldList());
    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.
    The "adapters.xml" file you attached is good for the Java Adapter (inprocess) but with your PHP Remote Adapter you should use something like this:
    <?xml version="1.0"?>
    <adapters_conf id="HELLOWORLD">
     
      <metadata_provider>
        <adapter_class>com.lightstreamer.adapters.metadata.LiteralBasedProvider</adapter_class>
      </metadata_provider>
     
      <data_provider>
        <adapter_class>com.lightstreamer.adapters.remote.data.NetworkedDataProvider</adapter_class>
          <param name="request_reply_port">7001</param>
          <param name="notify_port">7002</param>
          <param name="timeout">36000000</param>
      </data_provider>
     
    </adapters_conf>
    Really I heartily thanking you,

    Just now i could get understand about Lightstreamer and its adapter and client files. Too much of thanks to you. Based on this i have to develop stock market rates to client. We are developing application for bullion client. In that we are getting market rates from one third party application and we will add some of the margin and will display to users. Now i used ajax with settimeout() function to read file and display to client browser for every 200 mil second. Please give me some ideas to do this using lightstreamer. I got some basic points if you give some ideas means i can improve my application using lightstreamer.

    And also i'm getting error in my php coding like
    Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\lightsample

    Because getting error by indeterminate looping
    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);
    }

    For this i have update php.ini file and changed max_execution_time = 36000000

    now my browser continuously running. Is there any problem by this

    How can i overcome this. Thanks advance
    You can refer to this demo (the source code of the example is also provided) which shows a simple Stock-List client updated with real-time data generated by a simulator and injected via Lightstreamer. We provide example of the Adapter implementation both in Java and in C#.NET.

    Specifically about your case, you should build a Data Adapter that connects with the third-party application to receive the market rates and generate Items to which clients subscribe and receive all updates in real time.

    Do you mean that to every different users you should apply different margins or the margins are the same for all the clients?
    Based on this response there could be some different implementation choices.

    About "Maximum execution time ..." error please you can refer to this previous post:

    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

    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)
    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



    but if you have no chance to run the PHP code from a command line and not as a page I do not have better suggestions than your solution of increase the timeout.
    I have referred LightStreamer Demo and i have written the adapter in c#.

    In StandaloneLauncher.cs(in main function) file i have modified as

    string host = "localhost";
    int rrPortMD = 6650;
    int rrPortD = 6651;
    int notifPortD = 6652;
    string name = null;

    and i have modified the code in ExternalfeedSimulater.cs file with my real time data.

    And also i have created the adapters.xml file as

    <adapters_conf id="GARGTEST">


    <metadata_provider>
    <adapter_class>com.lightstreamer.adapters.remote.metadata.NetworkedMetadataProvider</adapter_class>
    <param name="request_reply_port">6652</param>
    <param name="connection_recovery_timeout_millis">10000</param>
    <param name="first_connection_timeout_millis">10000</param>
    <param name="close_notifications_recovery">unneeded</param>
    </metadata_provider>


    <data_provider name="GARGADAPTER">
    <adapter_class>com.lightstreamer.adapters.remote.data.NetworkedDataProvider</adapter_class>
    <param name="request_reply_port">6650</param>
    <param name="notify_port">6651</param>
    <param name="connection_recovery_timeout_millis">10000</param>
    <param name="events_recovery">use_snapshot</param>
    </data_provider>


    </adapters_conf>

    My client file looking like,
    <script>
    var hostToUse = document.location.protocol == "file:" ? "http://localhost:8080/" : document.location.protocol+"//"+document.location.hostname+(document.location.port?":"+document.location.port:"");


    define("lsClient",["LightstreamerClient","StatusWidget"],function(LightstreamerClient,StatusWidget) {
    var lsClient = new LightstreamerClient("http://localhost:8880/","GARGTEST");
    lsClient.connectionSharing.enableSharing("RemoteStockListConnection", "ATTACH", "CREATE");
    lsClient.addListener(new StatusWidget("left", "0px", true));
    lsClient.connect();

    return lsClient;
    });
    </script>
    <script type="text/javascript">


    require(["lsClient","Subscription","StaticGrid"],
    function(lsClient,Subscription,StaticGrid) {

    var stocksGrid = new StaticGrid("stocks",true);
    stocksGrid.setAutoCleanBehavior(true,false);
    stocksGrid.addListener({
    onVisualUpdate: function(key,info) {
    if (info == null) {
    return;
    }
    var cold = (key.substring(4) % 2 == 1) ? "#eeeeee" : "#ddddee";
    info.setAttribute("yellow", cold, "backgroundColor");
    }
    });

    var stockSubscription = new Subscription("MERGE",stocksGrid.extractItemList(),stocksGrid.extractFieldList());
    stockSubscription.addListener(stocksGrid);
    stockSubscription.setDataAdapter("GARGADAPTER");
    stockSubscription.setRequestedSnapshot("yes");

    lsClient.subscribe(stockSubscription);
    });


    </script>


    In Lightstreamer/adapters/gargtest/lib i had put the file ls-proxy-adapters.jar

    But when i run this code getting error

    http://localhost:8880/lightstreamer/create_session.js creation failed(continuously trying to connect session but getting error)
    If the create_session.js fails the most likely reason is that the Lightstreamer server is not listening on the specified port; this can happen if the startup procedure fails or never completes.
    But in your case, that involve remote Adapters, as long as a connection to a remote Metadata Adapter is still missing, all client requests will be refused.

    So, please check if the Lightstreamer server is started normally and that all the remote Adapters (port: 6650, 6651, 6652) are connected properly. If it is the case you can also post here some snippets of server log.

    Regards.
    How to check all the remote Adapters (port: 6650, 6651, 6652) are connected properly in Lightstreamer. I used to monitor this like http://localhost:8880/monitor/ But i couldn't check.There is no option to view port
    You are right, in the Lightstreamer monitor console you find mainly info about the clients connections and server status (memory and number of threads used ...).

    To verify that all Remote Adapters are connected you have to look in the server log ("LS_HOME / logs / lighstreamer.log") for pair of messages like these:

    Waiting for a connection on port 6650...
    ...
    Connected on port 6650
    I found the issue and corrected. Thank you very much.

    And i have one more doubt how to send response with different values for multiple client.

    1)In my case clients are separated by groups. If i connect all the clients with lightstreamer how can i identify clients belonging groups.
    2)How to send client id to server(ie: User id) based on the client id how to send response for respected clients
    In a case like yours, that involves private messaging, you just need to add a little bit of implementation in your Metadata Adapter.

    We assume that on the client side you set the user ID by this function. On the adapter side, with the NotifyUser method you can identify the user and assign him to the correct group. Then in the GetItems method you can customize the Item (i.e. "MyItem" became "MyItem_GroupA" or "MyItem_GroupB" depending on which group the user belongs).

    Now you can feed the item "MyItem_GroupA", "MyItem_GroupB", ... independently with the quotes appropriately corrected and users will receive only those of their group in a transparent way.

    For a further discussion on the topic of private messages, please take a look at this thread.

    Hope that helps.