How to: Adding wildcard pages to robots.txt

Sometimes we want to exclude a page from search engines. For example, repetitive pages that might lead to page rank penalties.

If you want to exclude pages with a specific name from several locations in your site – for example you might have a comments.php or a help.php in multiple parts of your site, and you want to hide it from search engines, you need to modify robots.txt.

Here is how you do it:
1) Create or edit robots.txt in the root of your site
Continue reading

Generate and Format Last Updated in PHP

As a reader of many on line product reviews, I am always interested in the time this review is relevant for. As time pass things change and review get stale.

If you have this need as a webmaster and your review is file based (as appose to DB) you can use the filemtime function to automatically generate the last updated:


$LAST_UPDATED = date ("F d Y", filemtime('review.php'));

Where review.php is the file that holds the product review for example.
Continue reading

How to: Redirect 404 (page not found) pages in PHP and Apache – Internet Explorer problem

Sometimes you want your client to see a different page then the default 404 (page not found)
To do this you just need to add and entry to .htaccess file on your web folder:

ErrorDocument 404 /404err.php

404err.php is an example of the PHP page you want the Apache to serve instead of the apache default.
Continue reading

Useful tool – Vista Battery Saver

Yesterday, I lectured on environmental technologies and had a chance to present, what I think is, one of the most useful ,open source downloads for people who use Vista on their laptop.

A few months ago, my friend Tamir Khason has released a super cool open source application called Vista Battery Saver.

"This tinny program will save up to 70% of your battery by disabling those nice, but greedy Vista features. Running in task bar with private workset of 5.5M and 0% CPU it will do all work for you, by enabling and disabling customizable features when power source changed or battery power fall under certain percent."

vista battery saver

Saving battery time does not only prolong the time you can use your laptop without recharging, it also reduces the total energy your computer uses. you might think it is nothing but this makes great difference if all of us use it (plus, it is free!).

Does the open source professional services business model suck?

Today I participated and lectured at an open source event. It was great to meet enthusiastic people that believe in something bigger then themselves. These events are always a mixture of young people full of vigor and need for rebellion as well as more balanced older people that have believed in open source for a long time.

I have been intrigued with open source and open source business models for a long time now, so I might belong to the second group.

Anyway, in the keynote, the speaker talked about open source business models, saying that the professional services business model is better then proprietary code business model because it provides real value to the end consumer and because you get a return of your investment in this business model.

Well, I have my reservations:money

1) I have seen companies misuse the professional services business model (open source or not) – selling poor service and wasting the clients time and spending his money with "experts" that know very little.

2) There is no motivation for a company, basing its business on open source development and professional services, to create simple and easy to use application. This is because simple and easy to use applications do not generate the need for professional services. Professional services thrive on complexity and difficulty.

opensource-110x953) Professional services business model (open source or not) can create a tension between the service provider that wants to prolong the duration and manpower sent on a project and the client how wants exactly the opposite

4) I am not sure the open source professional services business model is a big enough business to drive the entire market to open source products or to sustain open source companies.

I have once personally been told in an open source project – “Do not add this auto-configuration feature, it will kill our professional services” of course after a long “discussion” we added the feature, but the potential to provide a sucky product just to satisfy this open source business models was still there.

I am still thinking about and waiting for the business models that can really sustain and grow a  large scale and successful open source company.


You might also what to read how to spot a good software consultant

PHP calling .NET – PHP to WCF calls with parameters

In my last post I provided an example of PHP calling a .NET windows communication foundation web service. The PHP invoked the .NET service with no parameters, getting the time on server.

Sometime (well, most of the times) you need to pass parameters to the .NET web service. for example you might want to pass a client ID and get back its account balance.

 

Here is what you do:

First create a "out of the box" windows communication foundation (WCF) WCF service library project ( I used Visual Studio 2008) .

Then, modify the project files according to the files posted bellow. 

My server side WCF code looks like this:

1)  Service1.cs –

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfServiceLibrary2
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

    }
}

2)  IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfServiceLibrary2
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

    }   
}

The server side WCF application configuration (App.config) file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!– When deploying the service library project, the content of the config file must be added to the host’s
  app.config file. System.Configuration does not support config files for libraries. –>
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary2.Service1" behaviorConfiguration="WcfServiceLibrary2.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary2/Service1/" />
          </baseAddresses>
        </host>
        <!– Service Endpoints –>
        <!– Unless fully qualified, address is relative to base address supplied above –>
        <endpoint address ="" binding="basicHttpBinding" contract="WcfServiceLibrary2.IService1">
          <!–
              Upon deployment, the following identity element should be removed or replaced to reflect the
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
              automatically.
          –>
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!– Metadata Endpoints –>
        <!– The Metadata Exchange endpoint is used by the service to describe itself to clients. –>
        <!– This endpoint does not use a secure binding and should be secured or removed before deployment –>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary2.Service1Behavior">
          <!– To avoid disclosing metadata information,
          set the value below to false and remove the metadata endpoint above before deployment –>
          <serviceMetadata httpGetEnabled="True"/>
          <!– To receive exception details in faults for debugging purposes,
          set the value below to true.  Set to false before deployment
          to avoid disclosing exception information –>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

 

Note my blog post about the importance of setting this WCF service binding to basicHttpBinding

The PHP side of the application code looks like this:

<h1>
<?php

try{
    $client = new
        SoapClient(
            "
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary2/Service1/?wsdl"
        );
    $params = array(‘value’=>"3");
    $webService = $client->GetData($params);
    $wsResult = $webService->GetDataResult;
    print  $wsResult;
} catch (Exception $e) {
    print  ‘Caught exception: ‘.  $e->getMessage(). "\n";
}

?>

</h1>

 

This is very similar to the previous example of PHP to WCF communication, only here the PHP passes an array of parameters to the WCF web service:

$params = array(‘value’=>"3");
$webService = $client->GetData($params);

In my next post I will show how to investigate the WCF service and learn the parameters it requires and their soup names.


PHP calling .NET – PHP to WCF communication

I am done doing my first PHP to .NET interoperability example. In this example a PHP page calls a windows communication foundation (WCF) service in .NET

Here is what we want to create:

php-wcf 

 

First create a "out of the box" windows communication foundation (WCF) WCF service library project.

Then, modify the project files according to the files posted bellow.

My server side WCF code looks like this:

1)  Service1.cs –

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfServiceLibrary1
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config.
    public class Service1 : IService1
    {
        public string GetData()
        {
            return string.Format("Time on server is " + System.DateTime.Now.ToString());
        }

    }
}

2)  IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfServiceLibrary1
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData();

        // TODO: Add your service operations here
    }

}

The server side WCF application configuration file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!– When deploying the service library project, the content of the config file must be added to the host’s
  app.config file. System.Configuration does not support config files for libraries. –>
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
        <!– Service Endpoints –>
        <!– Unless fully qualified, address is relative to base address supplied above –>
        <endpoint address ="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
          <!–
              Upon deployment, the following identity element should be removed or replaced to reflect the
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
              automatically.
          –>
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!– Metadata Endpoints –>
        <!– The Metadata Exchange endpoint is used by the service to describe itself to clients. –>
        <!– This endpoint does not use a secure binding and should be secured or removed before deployment –>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <!– To avoid disclosing metadata information,
          set the value below to false and remove the metadata endpoint above before deployment –>
          <serviceMetadata httpGetEnabled="True"/>
          <!– To receive exception details in faults for debugging purposes,
          set the value below to true.  Set to false before deployment
          to avoid disclosing exception information –>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Note my blog post about the importance of setting this WCF service binding to basicHttpBinding

 

The PHP side of the application code looks like this:

<h1>
<?php

try{
    $client = new
        SoapClient(
            "
http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/?wsdl"
        );

    $webService = $client->GetData();

    $wsResult = $webService->GetDataResult;

    print  $wsResult;

} catch (Exception $e) {

    print  ‘Caught exception: ‘.  $e->getMessage(). "\n";

}

?>

</h1>

The only thing you need to modify is the URL parameter passed to the SoapClient to match your WCF service URL.

If you want to pass parameters to the WCF web service call please see this blog post.

If you have any questions please post a reply.

Language syntax’s, performance, PHP, Ruby, Java and who’s better? Ahhhh!

Language syntax’s, performance, PHP, Ruby, Java and who’s better? Ahhhh!
I was reading on The Server Side and came across this post:
http://www.theserverside.com/news/thread.tss?thread_id=43020#221954
which is part of this overall discussion:
Tim Bray: Java is less scalable than PHP
The overall topic is interesting, especially since the premise is further clarified by the person who did the presentation, who goes on to point out that, what he’s attributed to having said, is not what he actually said! Making a good point of the idea that context, presentation, etc. all affect the meaning of any statement whether it’s with humans or computers.
Having said, that, my post starts off dinging him on a better syntax for the Lisp and Smalltalk he shows or mentions and then goes into a rant on our current state of affairs.

So here it is:

The Lisp and Smalltalk can be just as simple.
Here is an example:


(loop for n from 1 to 10 do
(format t "i is ~A~%" n))
==>
i is 1
i is 2

< removed for brevity >
i is 9
i is 10

Smalltalk is just as easy:


1 to: 10 do: [:each | Transcript show: "i is ", each]

The post also had this quote:
These last 30+ years have taught us that most programmers feel reasonably >comfortable with languages that follow the syntax pioneered by C and >Basic.

I’m not so sure I’d agree with that. There are many programmers that did quite well with Lisp, COBOL, ADA, Smalltalk, RPG, Perl, shell, Fortran, etc. The things and ideas your exposed too, along with the multitude of ways that you learn to think, affect more about which languages you are comfortable with than syntax. I started with Basic, Forth and Assembler, but once I learned Lisp and Smalltalk, I found that they allowed me to think in much more flexible and effective ways and to solve problems of greater magnitude. I continue to find that true to this day.
While I can get things done in Java or C++, the work and bastardization of my ideas that must take place due to the constraints of the language structures and features, make me do much more work than I’d like. And this is even with all the frameworks etc., I can not easily encode many ideas without ending up in pattern-itis and code bloat. And on top of that quite a few of those frameworks have there own views of the world and structures/patterns I must conform too.
I think it is lost on today’s programmers and enterprise developers that the Smalltalk and Lisp systems of the late 70’s and going through the early 90’s did windowing, networking, email, threading, document systems, etc. all on systems that used about 1/5 th the code as compared to C/Unix versions of similiar tools. We also get many of the techniques for optimization of the JVM and OO systems from work on or inspired by those early systems. (Hotspot came from Strongtalk and Self work) To this day those systems can perform just as well or better than the JVM.
But like I said, I think a lot of this is lost on most programmers today. They tend to worry about IDE refactoring across many hundreds of files (what happened to loose compling??), type inferencing (they don’t know that HotSpot doesn’t use most of the typing in the code, but chooses the best code path from cached run-time generated native code), they’re interface and delegation happy (while not learning from the bloat that caused in the MS COM world) and a lot refuse to open their minds to learn from many other languages, tools and approaches because it’s not the religion of today!
I’ve see a lot of this cycle and rhetoric before though, so history is just repeating itself. The C++ prgrammers poo-pooed the Smalltalkers and at first the Java guys as well, till they themselves became Java users. As Java pulled in VM technology from Lisp and Smalltalk and got faster, and started to run on as many platforms as Smalltalk (most people don’t know that in the early 90’s that Smalltalk ran on approximately 40 platforms in a true write-once run-anywhere mode not the dream Java had for the first few years), more and more programmers jumped on the bandwagon.
Now the Java world is being shacken up, but this time, they are sounding like the C++er’s of old, but it’s funny, because some of the Java old guard are leaving the religion and seeing the bigger world again. Not only that, they’ve seen that you can get more and more dynamic and still perform and have safe tested systems. They’ve also seen that all those patterns and work arounds they’ve been applying to try to get back that dynamic behavior they’ve so wanted aren’t needed as much or at all in some of these new languages and systems.
We still here a common theme though! Most still want type safety. Lisp proves you can have both worlds and people are going that way. I think people want a language that lets you add type safety as needed. It’s the future and even the guys as SUN know that other languages are coming and they are maneuvering to try to be ready for the next big thing.
Am I saying Java dead or less useful? Not at all! What I am saying is that as we wish for more and challenge Java more, we are wanting more of what we already have great examples of. We must continue to open our minds to not only what is new, but to what is old but new to us! We need to see the power of that old stuff, and remember to be humble, b/c the reality is that a lot of what we think is new has already been done almost 30 years ago by some very smart people, many of whom still go to work today like you and me, but who are very patient, knowing that great things have a way of reappearing.
Keep your eyes open and remember just as Java has opened peoples eyes and incorporated many lessons from what was done before it, it can continue to do so, but it may well be passed by, by some new language and toolset. SUN is trying to make sure they are a part of that revolution or evolution whichever one it is.

Java brought together in one package a lot of the things that people needed and wanted at the time, such as familiar syntax, platform portability, basic abilities to do netowrking and web work, then added everything that people learned from the old CICS systems and CORBA enterprise knowledge. That’s a big chunk of computing and they assembling it all together in Java and it is a great feat! Great for all of us!
Now some people are looking back at other things that were learned and achieved and hoping to add the best of those other ideas as well. Quite a lot of these “new” things were again found in those old research systems. (Not suprising really). I for one can’t wait. They’re awesome systems.
In the interest of disclosure, I have two Lisp Machines, several Smalltalk systems and am a devout believer in the dynamic, exploratory programming style that those systems encourage. I have worked on and solved many large mission critical and corporate applicaitons with said tools as well doing the same for similiar systems in Java and C++.
Off the high horse now… and I hope you’ve found this thought provoking!
[on java]