What is Pike?

Pike is a language similar to C and C++. It is very powerfull and fast. The Caudium Webserver is based on this language and some C code as well. Here is some example of code you can use to help you to some code for this marvelous webserver.

HTTP Raw request

The HTTP Raw request can be get by id->raw like in this code :

<pike>
 return sprintf("<PRE>%O</PRE>",id->raw);
</pike>
You can test it.

How to play with images and Pikescript

Caudium (and Roxen) can run pikescripts. This can allow you to make some good image works in live :).

//inherit "roxenlib";		// If Roxen
inherit "caudiumlib";		// If Caudium

int no_reload(object id)
{

 if(!id->variables->reload)
   return 1;
 return 0;
}

mixed parse(object id)
{
  string where=dirname(__FILE__) + "/";
  object o = Image.load(where + "max2000.gif");
  int i;

  if (!id->variables->where)
   i = 5;
  else
  {
   if((int)(id->variables->where) >= 20)
    i = 20;
   else if((int)(id->variables->where) <=0)
    i = 2;
   else
    i = (int)(id->variables->where);
  }

  o = o->box( i*5, i*3, i*5+30, i*3+30 );
  return http_string_answer(Image.GIF.encode(o),"image/gif");
}
You can test it in action here or here.

Get nice status of Caudium/Roxen server

Using pike tags, you can get a nice status of a Caudium or Roxen webserver :

<table>
<tr><td><pike>return roxen->full_status();</pike></td>
<td>
 
<table bgcolor=black cellpadding=4 cellspacing=0 border=0><tr><td>

<diagram align=center valign=middle type=bar width=400 height=400
name='Bande passante des Sites'
 horgrid tonedbox='lightblue,lightblue,white,white'>
<data xnamesvert xnames form=column>

<pike>
string out=""; 
int count=10;
int otherHits=0;
float otherMb=0; foreach(Array.sort_array(caudium->configurations,
                         lambda(object a, object b) {
  return a->sent < b->sent;
  }),object o) {
  if ((count--) >0) {
    out+=sprintf("%s\t%.2d\t%.2f\n",
                 (string)o->query("MyWorldLocation"),
                 o->sent / 1024 / 1024,
                 o->requests/100.0);                                 
  } else {
    otherHits+=o->requests;
    otherMb+=o->sent / 1024 / 1024;
  } } 

return out;
</pike></data> 
<legend separator=,>Volume en Mo,Requetes (x 100)</legend>
</diagram>
</td></tr></table></td></tr> </table>
</data>
You can see the output of that script.