play radio stream with gstreamer

Due to the fact that I started to play with gstreamer I have needed audio video inputs.

as we know the best source for such content is the NET I just search for some radio streams and found two Austrian local senders.

Ö3 http://oe3.orf.at/ => mms://gcssrv.pkf.speednet.at/WSX/oe3_live

88.6 http://886.at/   => http://radiostream.de/stream/36795.pls

For  Ö3 it is easy,  just use on gentoo:

gst-launch-0.10 -v playbin2 uri=mms://gcssrv.pkf.speednet.at/WSX/oe3_live

If you have another distribution maybe it is enough gst-launch.

For the 88. 6 is it a little bit difficulty, due to the fact that the link is a multimedia playlist.

  1. get the content of the pls file
curl -s http://radiostream.de/stream/36795.pls|egrep File
  1. take one of the streams and handover it to the gstreamer
gst-launch-0.10 -v playbin2 uri=http://ber.radiostream.de:36795

That’s it, have fun ;-)

VNC and SSH for portforwarding

The problem: There is only a Windows PC with a Internet connection and you need to connect to some unix machines behind this machine with ssh, HOW?

The solution: Use a VNC (e.g.: TightVNC) and OpenSSHD for Windows on your Linux box.

Detail description:

Pre required components:

  1. A VNC Client, I have used the vncviewer from TightVNC
  2. OpenSSHD for Windows
  3. Admin access to the Windows machine

OK now we can start with the necessary steps.

Windows Part

1.) Install TightVNC on your Windows machine.

2.) Install OpenSSHD on your Windows machine.

3.) Read the quickstart.txt from OpenSSHD.

Here the part which I think ist the most important one:

Configuration
1.  Open a command prompt and change to the installation directory
    (Program Files\OpenSSH is the default).
2.  CD into the bin directory.
3.  Use mkgroup to create a group permissions file. For local
    groups, use the "-l" switch. For domain groups, use the
    "-d" switch.
    For both domain and local, it is best to run the command twice
    (remember to use >>, not >). If you use both, make sure to edit
    the file to remove any duplicate entires.
    mkgroup -l >> ..\etc\group      (local groups)
    mkgroup -d >> ..\etc\group      (domain groups)
4.  Use mkpasswd to add authorized users into the passwd file. For
    local users, use the "-l" switch. For domain users, use the
    "-d" switch.
    For both domain and local, it is best to run the command twice
    (remember to use >>, not >). If you use both, make sure to edit
    the file to remove any duplicate entires.

    mkpasswd -l [-u <username>] >> ..\etc\passwd      (local users)
    mkpasswd -d [-u <username>] >> ..\etc\passwd      (domain users)

    NOTE: To add users from a domain that is not the primary domain
          of the machine, add the domain name after the user name.
    NOTE: Ommitting the username switch adds ALL users from the
          machine or domain, including service accounts and the
          Guest account.

5.  Start the OpenSSH server.

       net start opensshd

6.  Test the server. Using a seperate machine as the client is best.
    If you connect but the connection immediately gets dropped,
    reboot the machine with the server and try connecting again.

Pay attention that you have a Windows user with a password. This password will be used for the SSH connection.

4.) Start TightVNC and go to the Properties.

5.) Switch to the Administration tab and activate the loopback connections

tightvnc options

6.) Now we are done on the Windows PC

Linux Part

1.) Install TightVNC on your unix / linux machine.

2.) Start a shell

3.) Type in the target server as SECOND -L

(this must be in one line!)

export VNC_VIA_CMD=’/usr/bin/ssh -f -L %L:%H:%R -L 4711:<DESTINATION_SERVER_IN_THE_REMOTE_LAN>:22 <WINDOWS_USERNAME>@%G sleep 20′

4.) Connect to the Windows connected PC with vncviewer

(this must be in one line!)

echo <YOUR_TIGHT_VNC_PW>|vncviewer -compresslevel 4 -quality 4 -bgr233 -autopass -via <IP_OF_THE_INTERNET_CONNECTED_PC> <IP_OF_THE_INTERNET_CONNECTED_PC>

e.g.:

echo aaa|vncviewer -compresslevel 4 -quality 4 -bgr233 -autopass -via 192.168.1.41 192.168.1.41

5.) Now you can connect via port 4711 to the <DESTINATION_SERVER_IN_THE_REMOTE_LAN>

ssh -p 4711 127.0.0.1

EH Voila we are now connected to the remote site ;-)
Here a picture because its easier to understand ;-)

Connection Flow

Country select box in symfony setWidgets

For my register form was the requirement to select from which Country a user is.

Symfony have a nice feature called select_country_tag which I wanted to use in the $this->setWidgets() in the mysfGuardFormSignin.class.php the problem is that the select_country_tag gives not the array back.

After a little bit ‘reverse engineering’ the solution for me is like this

    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $countries = $c->getCountries();

here the full class

less lib/form/mysfGuardFormSignin.class.php
<?php

class mysfGuardFormSignin extends sfForm
{
  public function configure()
  {
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $countries = $c->getCountries();

    $this->setWidgets(array(
      'username' => new sfWidgetFormInput(),
      'email' => new sfWidgetFormInput(),
      'password' => new sfWidgetFormInput(array('type' => 'password')),
      'country'  => new sfWidgetFormSelect(array('choices' => $countries)),
    ));

    $this->setValidators(array(
      'username' => new sfValidatorString(),
      'email'    => new sfValidatorString(),
      'password' => new sfValidatorString(),
      'country'  => new sfValidatorString(),
    ));

    $this->validatorSchema->setPostValidator(new sfGuardValidatorUser());

    $this->widgetSchema->setNameFormat('signin[%s]');
  }
}

Which language for Webdevelopment php python perl ruby or java

I have searching for a long time for the right webframewor to develop a rather small Webapplication.
The requirement was:

  1. Usermanagmemtn, ACL
  2. Manage Files to download by Userpermission
  3. run behind nginx

I have developed in all of this languages in the past, some of them in mor deep then in the other.

I have take a look about different frameworks in this languages

  1. Perl
  2. Python
  3. PHP
  4. Ruby
  5. Java

The main decision to go to the php based symfony framework was:

  1. It is easy to learn and relativly good documented
  2. php-fm
  3. I know php more or less good, not better then perl but the setup was easier to create.
  4. There are more php known persons in the current company.

My reasons why I have not choose one of the differnt languages to work:

  1. Java: due the fact that you need to compile it, so you need a IDE (ala. Eclipse). It takes more time to see if you change works.
  2. ruby & python: I haven’t not enough experience with it. This language looks very nice and easy to learn but it wasn’t necessary that I learn it, yet ;-)
  3. perl: I have develop a lot of perl modules and code in the past but for now I like php more.

So as you can see it is not very academic more pragamtic ;-) .

High performance PHP

If you have the need to run php with a very high traffic you should think about the follwoing setup.

Don’t think it will work in 5 minutes and you don’t need some knowledge about how to setup an webserver and a php application, you definitely need it.

If you think this is a step by step description for people which only want to copy and past commands and it works then you are wrong here, please take a websearch engine for a alternative description.

What you need:

  1. nginx http://www.nginx.net/
  2. php-fm http://php-fpm.anight.org/
  3. php http://www.php.net/
  4. a compile environment
  5. the development libraries for the wanted php features and libxml2
  6. A clear test scenario and target how many requests per second should be reached on static and dynamic part.

How you can build this environment:

  1. Extract, build and install nginx http://wiki.codemongers.com/NginxGettingStarted
  2. Extract, build and install php-fm http://php-fpm.anight.org/docs.html
  3. configure nginx for fast-cgi proxying http://wiki.codemongers.com/NginxHttpFcgiModule

High Performance View

A brief description how the flow is:

  • A request comes to nginx
  • He takes a look into his config to find the right location or server config
  • If the static content rule matches then he will deliver the content directly from the disc
  • If the dynamic rule matches the he will contact php-fm, which manage the php-instances
  • php-fm execute the php script and send the dynamic content back to nginx
  • nginx sends the content back to the client

There are some pitfalls:

  1. client_body_buffer_size
  2. fastcgi_buffers*

You should take your time to find the right config setup for nginx and php-fm to be able to fulfill the assumed traffic.

I have started to translate the russian documentation, which is still not complete.

You can take a look here:

why_fastcgi_en

current_php_fastcgi_problems_en

extra_features_en

use the event ports in nginx

Solaris have since version 10 a new polling infrastrucutre Event Ports here a more detailed article about Event Completion Framework. Adam Leventhal wrotes in his Blog for him this is one of the top 20 best thing in Solaris 10.

By default nginx do not use this event methode due to the fact that there was some security related problems Security Vulnerabilities in The Solaris Event Port API May Result in a Denial of Service (DoS) Condition and  Vulnerability in the Solaris 10 Event Port Implementation May Lead to a System Panic, Resulting in a Denial of Service (DoS) if you have a newer Version or applied the Patch you should use the event ports in nginx.

You only need to add

use eventport;

in the events { … } section. If you don’t add this then nginx by default us the /dev/poll method.

More about the possible polling methods can be found here.

haproxy on Opensolaris 2008.05

When you want to build haproxy on Opensolaris 2008.05 you need the gcc and the gmake due to fact that the Sun CC does not support fully the C99 standard and the Makefile use GNU Make features.

I have tried to build haproxy with -xc99 but it was unable due the following code in src/client.c

/* Note: must not be declared <const> as its list will be overwritten */
static struct acl_kw_list acl_kws = {{ },{
{ “src_port”, acl_parse_int, acl_fetch_sport, acl_match_int },
{ “src”, acl_parse_ip, acl_fetch_src, acl_match_ip },
{ “dst”, acl_parse_ip, acl_fetch_dst, acl_match_ip },
{ “dst_port”, acl_parse_int, acl_fetch_dport, acl_match_int },
#if 0
{ “src_limit”, acl_parse_int, acl_fetch_sconn, acl_match_int },
#endif
{ “dst_conn”, acl_parse_int, acl_fetch_dconn, acl_match_int },
{ NULL, NULL, NULL, NULL },
}};

and some other code. I think SUN should make his cc compliant so that we are able to build haproxy with there compiler ;-) . When you install the gcc and add the follwoing statement into the Makefile

-I$(PCREDIR)/include/pcre

in both *_PCRE sections then you are able to compile haproxy with the follwoing options

gmake -f Makefile TARGET=solaris USE_STATIC_PCRE=1 CPU=i686

for the final build you must rearrange the link line, this line works for me

gcc -g -o haproxy src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o src/time.o src/fd.o src/regex.o src/cfgparse.o src/server.o src/checks.o src/queue.o src/client.o src/proxy.o src/proto_uxst.o src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o src/senddata.o src/dumpstats.o src/proto_tcp.o src/session.o src/hdr_idx.o src/ev_select.o src/acl.o src/memory.o src/ebtree.o src/eb32tree.o src/ev_poll.o -L/usr/lib -Wl,-Bstatic -Wl,-Bdynamic -lnsl -lsocket -lpcreposix -lpcre

The point was, which looks to me, that the libs must be added as last options.

nginx build on opensolaris with SunStudio

Today I was interested if the latest nginx (nginx-0.7.1) is able to build on the opensolaris box and YES it does ;-)

1.) get it

wget http://sysoev.ru/nginx/nginx-0.7.1.tar.gz

2.) extract it

gtar xfvz nginx-0.7.1.tar.gz

3.) build it

cd nginx-0.7.1 && ./configure –prefix=$HOME/servers/nginx –with-http_ssl_module –with-debug –with-cc=/opt/SunStudioExpress/bin/cc

It’s so easy, thanks Igor.

Open Solaris 2008.05

Today I got the Opensolaris installation over the Virtualbox.

It looks much nicer with gnome but since Solaris 9 and 10 there was a lot of differences like nwamd and some other ‘typical’ Systemadmin commands.

I’am curious about the new features and handling ;-)

My interests

I like to work with nginx and haproxy and all of the high performance small resources issue.

You can find me in xing or post a message to contact me.

First Entry

Hi all,

this is the BLOG of Aleksandar Lazic.
I hope this will not be ‘yust another blog’ but we well see in the future ;-)