Silverlight with PHP

I do not really need to tell about the Silverlight and its power, since it is apparent. But at the same time I cannot keep mouth shut with the features that Silverlight offers. I have been working on WPF and Silverlight these days. And Just wondering the power the Silverlight has over the Web Apps. It drives me crazy especially compared to ASP.NET Ajax.

What an effective and an easy way to build RIAs. Wondering about the Silverlight architecture and how the mixture of XAML and the managed code sit on the back of the Silverlight.js. Really Excellent.

Using the Silverlight with ASPX is OK, what about with the other languages. Of course not a big deal. Here I explained how to use Silverlight in your PHP application with the C# managed code.

Create a simple PHP file that can take your name and say Hello !


The above PHP script gets post to itself and say Hello.

Now build the Silverlight in VS 2010, when creating the Silverlight application project select the temporary hosting in an HTML file rather than the Web project. This will create an HTML where your Silverlight object is embedded; it would be easy to get the code later.

Put the following in the Layout Grid – XAML Code



Code for button1_Click event in the MainPage.xaml.cs



Now we have the PHP file and the Silverlight application, Let’s put them together.

I’m hosting the PHP using the WAMP, Create a folder SilverlightPHP and save the above PHP file as index.php (so it’s easy to access)

Browse your Silverlight application project folder and inside the Bin->Debug there would be a file with the extension of .xap (description says as XACT project file)

Copy that file and put it into the SilverlightPHP folder.

Then open the HTML file in the Silverlight application project folder (it’s also in the Debug folder)

copy the Javascript code and paste it inside the <head> </head> or keep it as separate .js file and link it.

Then copy the Silverlight embedding code from the HTML and paste it inside the body. You can set the size here.


Here rather than copying the .xap file to the target folder you can set the value to as the path of the .xap file.

Save the index.php

Then RUN !@# and have FUN.

The real amazing thing is this a very cool way to bring the RIA capability to our normal PHP apps. You can notice that when you click the Say Hello button of the PHP the page reloads but when you click the Say Hello button of Silverlight it is completely an asynchronous call to the Silverlight object model. (great AJAX feature). More than that here we use C#.NET and the PHP in the same web interface.



Live Streaming with MS Encoder 3

I’ll explain you how to do a live streaming using Microsoft Encoder 3. Me and my friends tried out this in our boarding place using a simple local area network and succeeded. It’s not a big deal of course. Most of the work (almost all) is done by the Encoder 3. If you have a powerful machine then you can stream to many number of hosts. Here is the way how to do it.

Install Microsoft Encoder 3 in your machine. And I assume you have the Encoder installed on your machine for the further explanation. I did this in my machine which is running on Windows 7 Professional.

I didn’t explain here how to create a peer to peer connection between two machines thus it will make the post big, but you can get plenty of resources in a simple googling.

Once you set up a network check whether both machines are accessible. In your browser type the other machine’s IP like this http://yourIP. If both machines are networked and if a server is running on port 80 you’ll get a response.  There are plenty of ways to check the connection but I recommend this here since for the Silverlight Live Streaming you need the IIS as well. By this check you make sure that both machines are connected and well as the IIS is ready to be used.

Then start the Encoder. Click on Live Encoding. Select your webcam as Live source and if you have a sound device select it as a Audio device. Cue your live source.(your webcam). In this time you could able to see your web cam’s screen in the Encoder preview panel. Select the output as Broadcast. (Default port will be 8080 you can change it if you want). You can also set the maximum number of connections here.

Hit the Start. That’s it you are live now in the internal LAN.

Open your Windows media player (or any other player which has network support). Type the following mms://yourmachineIP:8080.

Wow you are online…. Your peer also have to do the same thing. If you listen to his IP and if he listen to your IP then it’s a local Skype. A Local Skype without the Internet.

If you have another machine in your network with a media server you can publish to that point and ask the media server to handle the connections. Here we don’t have media server and I used the broadcasting, where the source and server is our local machine.

If you want to go even further and want to watch inside the browser as we watch live matches in the YouTube just put an object tag and make it’s source as the above address. Really cool real streaming over the web. 🙂

Yuppie !!! 🙂

But unfortunately Encoder doesn’t provide an SDK to use the feature in our own applications. I put a forum regarding this and I got the following answer from a Moderator

“Unfortunately you would need to have Encoder on both PCs to perform something like this since we don’t have a way to deploy our SDK any other way at the moment. Without revealing state secrets, I believe that "Live" mode is returning to the free sku in our next version, so all your peer(s) would need to do is install the free version and use your application based on our SDK.”

The link to the updated forum :

But in the Encoder 4 it comes with an SDK. But I did not put out my hands into that yet.