Feed von
Beiträge
Kommentare

Currently I had to use the fileinfo-Package on my development-system which is a MacBook Pro running MacOS 10.5 with Marc Lianages PHP-Package.

But sadly that does not contain the fileinfo-extension.

No Problem I thought: Installing a PECL-Extension isn’t hard work.

At least if it works….

Of course I ran into the problem that I couldn’t compile the fileinfo extension due to the following error-message

configure: error: Please reinstall the libmagic distribution
ERROR: `/private/tmp/pear/download/Fileinfo-1.0.4/configure' failed

I can’t be the only one that ran into the problem, I thought. And so it was.

While searching the internet, I generally found two ways to solve the problem.

  1. Use PHP 5.3, that already contains the package
  2. Install a complete second OperatingSystem beneath a perfectly working MacOS. Here for instance I found a way to get the installation working by installing the complete fink-package.

Using PHP 5.3 was no option for me, as we are developing for PHP5.2 and installing a second Operating System seemed somewhat oversized for the simple task of installing a small PHP-extension.

Back to the roots

So what was the original problem again? A missing installation of the libmagic-library. Event though the info-binary is installed on the MacOS I’m running, a shared libmagic-Library is missing.

So what the hell, why not compile one?

  • So I got myself the current binaries from http://www.darwinsys.com/file/ unpacked the source and pulled out the Terminal.

    cd /path/to/unpacked/source
    ./configure --prefix=/usr/local/libmagic
    make
    sudo make install
    

    That left me with a running shared library of libmagic in the folder /usr/local/libmagic/lib

  • Second I used the already loaded source of the fileinfo-extension that caused the error due to the missing libmagic-library.

    So I opened /private/tmp/pear/download/Fileinfo-1.0.4/configure with my favourite Text-Editor (currently it is TextWrangler) and went to somewhere around line 4212 and changed it from

    SEARCH_PATH="/usr/local /usr /usr/share/file"

    to

    SEARCH_PATH="/usr/local /usr /usr/share/file /usr/local/libmagic"

    and again took my Terminal to go to the fileinfo-directory and finally compile the fileinfo-extension

    cd /private/tmp/pear/download/Fileinfo-1.0.4/
    ./configure
    
  • Because of the apache2 on my MacBook Pro that somehow thinks it is running on a 64bit Machine, even though it definitely is a 32bit one – would be nice though – I had to adapt the build-process somewhat by compiling a universal-binary so that the extension will be loaded by the apache.

    Some info on that can be found here and here at Apples Developer pages

    So I ran the following command in Terminal

    make CFLAGS="-arch i386 -arch ppc64 -arch x86_64" LDFLAGS="-arch ppc -arch i386 -arch ppc64 -arch x86_64"
    sudo make install
    

    Aternatively you can export the CFLAGS and LDFLAGS variable by running these commands in Terminal:

    export FLAGS="-arch i386 -arch ppc64 -arch x86_64"
    export LDFLAGS="-arch ppc -arch i386 -arch ppc64 -arch x86_64"
    

    Then you can simply run

    ./configure
    make
    make install
    

    That’s been the hard bit.

  • Last Steps

    Now the only things missing are the integration into php and the restart of the WebServer.

    For integrating the extension into php I added a file to the php-Directory via

    vi /usr/local/php5/php.d/50-extension-fileinfo
    

    where I simply added the line

    extension=fileinfo.so
    

  • And finaly the restart of the WebServer with

    sudo apachectl restart (or graceful)
    

Now I can call a phpinfo-file and there should be a line stating that the fileinfoextension is enabled.

 Hyphenation is something not widely used on the internet.

But sometimes it is something you need to do in Browser-based applications.

Just think of a PDF-File created on the fly by an application and the text is hyphenated in very strange ways or not at all. All just because of an algorithm that might hyphenate english texts in one way or an other but certainly not german, french or other texts.

Weiterlesen &rauqo;

One day I ran into the trouble of having labes too long for the space they should go into.

In this special case I had a navigation area with a width of 150 pixel but the strings that had to go into the navigation where much longer.

So I decided that shortening the Labels by replacing the middle part by a ‘…’ would do the trick.

Here is the code for it.

fitText : function(element){
    cn=element.childNodes;
    node=document.createElement('div');
    node.setStyle({'float':'left',visibility:'visible','font-weight':700});
    document.body.appendChild(node);
    for(var i=0;i<cn.length;i++){
        if(cn[i].nodeType != Node.TEXT_NODE){
            continue;
        }
        origText=cn[i].data;
        text=cn[i].data.trim();
        if ( text == ''){
            continue;
        }
        wo=element.getInnerWidth();
	counter=0;
	fits=true;
	do{
            mid=Math.ceil(text.length/2);
            text1=text.substring(0,mid-counter);
            text2=text.substring(mid+counter);
            text=text1+text2;
            newText=text1+'...'+text2;
            tn=document.createTextNode(newText);
            node.appendChild(tn);
            w=node.getInnerWidth();
            if (w>wo){
                fits=false;
            }
            node.removeChild(tn);
            counter++;
        } while((w>wo)&&(text.length>0))
        if ( ! fits ){
            cn[i].replaceData(0,origText.length,newText);
            element.setAttribute('title',origText);
        }
    }
    document.body.removeChild(node);
    return true;
}

This code requires the Prototype API.

And I believe that there are a lot of possibilities to improve that bit of JavaScript.

TV-Browser and Growl

Ever wanted to find an electronic TV-Guide?

Some time ago I found TV-Browser. Very nice Tool.

One fancy feature was the Growl-Integration on MacOS-X.  Well at least until TV-Browser 2.7. Somehow the integration of Growl was broken under MacOS X 10.4. 

The complete information about this can be found in the TV-Browser-Forum

Well at least until yesterday.

I implemented this Patch and – voila – Growl notification works as expected.

For those who do not want to go through the hassle of compiling the plugin themselves:

Here you can download the compiled plugin that works for me under MacOS-X 10.4.11

 

 A long time ago I had to solve the problem of running PHP4 and PHP5 on the same machine.

After a bit of searching I came across a posting in the german PHP-Mailing-List at http://www.phpbar.de where Norbert Pfeiffer described a possible way.

I choose to adapt my apachectl-file so that not one single instance of the apache-webserver was started but 2 instances. One of which listened on port 80, the other one on port 81.

This of course requires a unique httpd.conf for each of the instances. 

So here is my version of an apachectl-file.

#!/bin/sh
#
# Copyright 1999-2004 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Apache control script designed to allow an easy command line interface
# to controlling Apache.  Written by Marc Slemko, 1997/08/23
#
# The exit codes returned are:
#	0 - operation completed successfully
#	1 -
#	2 - usage error
#	3 - httpd could not be started
#	4 - httpd could not be stopped
#	5 - httpd could not be started during a restart
#	6 - httpd could not be restarted during a restart
#	7 - httpd could not be restarted during a graceful restart
#	8 - configuration syntax error
#
# When multiple arguments are given, only the error from the _last_
# one is reported.  Run "apachectl help" for usage info
#
#
# |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
# --------------------                              --------------------
#
# the path to your PID file
PIDFILE=/var/run/httpd.pid
PIDFILE2=/var/run/httpd2.pid
PIDFILE3=/var/run/httpd3.pid
#
# the path to your httpd binary, including options if necessary
HTTPD="/usr/sbin/httpd -f /etc/httpd/httpd.80.conf"
HTTPD2="/usr/sbin/httpd -f /etc/httpd/httpd.81.conf"
HTTPD3="/usr/sbin/httpd -f /etc/httpd/httpd.8888.conf"
#.
# a command that outputs a formatted text version of the HTML at the
# url given on the command line.  Designed for lynx, however other
# programs may work.
LYNXBIN="curl"
LYNX="$LYNXBIN -dump"
#
# the URL to your server's mod_status status page.  If you do not
# have one, then status and fullstatus will not work.
STATUSURL="http://localhost/server-status"
#
# --------------------                              --------------------
# ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||

ERROR=0
ARGV="$@"
if [ "x$ARGV" = "x" ] ; then
    ARGS="help"
fi

for ARG in $@ $ARGS
do
    # check for pidfile
    if [ -f $PIDFILE ] ; then
	PID=`cat $PIDFILE`
	if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
	    STATUS="httpd (pid $PID) running"
	    RUNNING=1
	else
	    STATUS="httpd (pid $PID?) not running"
	    RUNNING=0
	fi
    else
	STATUS="httpd (no pid file) not running"
	RUNNING=0
    fi
#
# Check for second apache
    if [ -f $PIDFILE2 ] ; then
        PID2=`cat $PIDFILE2`
        if [ "x$PID2" != "x" ] && kill -0 $PID2 2>/dev/null ; then
            STATUS="httpd (pid $PID2) running"
            RUNNING2=1
        else
            STATUS="httpd (pid $PID2?) not running"
            RUNNING2=0
        fi
    else
        STATUS="httpd (no pid file) not running"
        RUNNING2=0
    fi
#
# Check for third apache
    if [ -f $PIDFILE3 ]; then
	PID3=`cat $PIDFILE3`
        if [ "x$PID3" != "x" ] && kill -0 $PID3 2>/dev/null ; then
            STATUS="httpd (pid $PID3) running"
            RUNNING3=1
        else
            STATUS="httpd (pid $PID3?) not running"
            RUNNING3=0
        fi
    else
        STATUS="httpd (no pid file) not running"
        RUNNING3=0
    fi

    case $ARG in
    start)
	if [ $RUNNING -eq 1 ]; then
	    echo "$0 $ARG: httpd (pid $PID) already running"
	    continue
	fi
	if $HTTPD ; then
	    echo "$0 $ARG: httpd started"
	else
	    echo "$0 $ARG: httpd could not be started"
	    ERROR=3
	fi
        if [ $RUNNING2 -eq 1 ]; then
            echo "$0 $ARG: httpd (pid $PID2) already running"
            continue
        fi
        if $HTTPD2 ; then
            echo "$0 $ARG: httpd2 started"
        else
            echo "$0 $ARG: httpd2 could not be started"
            ERROR2=3
        fi
        if [ $RUNNING3 -eq 1 ]; then
            echo "$0 $ARG: httpd (pid $PID3) already running"
            continue
        fi
        if $HTTPD3 ; then
            echo "$0 $ARG: httpd3 started"
        else
            echo "$0 $ARG: httpd3 could not be started"
            ERROR3=3
        fi
;;
    stop)
	if [ $RUNNING -eq 0 ]; then
	    echo "$0 $ARG: $STATUS"
	    continue
	fi
	if kill $PID ; then
	    echo "$0 $ARG: httpd stopped"
	else
	    echo "$0 $ARG: httpd could not be stopped"
	    ERROR=4
	fi
        if [ $RUNNING2 -eq 0 ]; then
            echo "$0 $ARG: $STATUS"
            continue
        fi
        if kill $PID2 ; then
            echo "$0 $ARG: httpd2 stopped"
        else
            echo "$0 $ARG: httpd2 could not be stopped"
            ERROR2=4
        fi
	if [ $RUNNING3 -eq 0 ]; then
            echo "$0 $ARG: $STATUS"
            continue
        fi
        if kill $PID3; then
            echo "$0 $ARG: httpd3 stopped"
        else
            echo "$0 $ARG: httpd3 could not be stopped"
            ERROR3=4
        fi

	;;
    restart)
	if [ $RUNNING -eq 0 ]; then
	    echo "$0 $ARG: httpd not running, trying to start"
	    if $HTTPD ; then
		echo "$0 $ARG: httpd started"
	    else
		echo "$0 $ARG: httpd could not be started"
		ERROR=5
	    fi
	else
	    if $HTTPD -t >/dev/null 2>&1; then
		if kill -HUP $PID ; then
		    echo "$0 $ARG: httpd restarted"
		else
		    echo "$0 $ARG: httpd could not be restarted"
		    ERROR=6
		fi
	    else
		echo "$0 $ARG: configuration broken, ignoring restart"
		echo "$0 $ARG: (run 'apachectl configtest' for details)"
		ERROR=6
	    fi
	fi
        if [ $RUNNING2 -eq 0 ]; then
            echo "$0 $ARG: httpd2 not running, trying to start"
            if $HTTPD2 ; then
                echo "$0 $ARG: httpd2 started"
            else
                echo "$0 $ARG: httpd2 could not be started"
                ERROR=5
            fi
        else
            if $HTTPD2 -t >/dev/null 2>&1; then
                if kill -HUP $PID2 ; then
                    echo "$0 $ARG: httpd2 restarted"
                else
                    echo "$0 $ARG: httpd2 could not be restarted"
                    ERROR2=6
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR2=6
            fi
        fi
        if [ $RUNNING3 -eq 0 ]; then
            echo "$0 $ARG: httpd3 not running, trying to start"
            if $HTTPD3 ; then
                echo "$0 $ARG: httpd3 started"
            else
                echo "$0 $ARG: httpd3 could not be started"
                ERROR3=5
            fi
        else
            if $HTTPD3 -t >/dev/null 2>&1; then
                if kill -HUP $PID3 ; then
                    echo "$0 $ARG: httpd3 restarted"
                else
                    echo "$0 $ARG: httpd3 could not be restarted"
                    ERROR3=6
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR3=6
            fi
        fi
	;;
    graceful)
	if [ $RUNNING -eq 0 ]; then
	    echo "$0 $ARG: httpd not running, trying to start"
	    if $HTTPD ; then
		echo "$0 $ARG: httpd started"
	    else
		echo "$0 $ARG: httpd could not be started"
		ERROR=5
	    fi
	else
	    if $HTTPD -t >/dev/null 2>&1; then
		if kill -USR1 $PID ; then
		    echo "$0 $ARG: httpd gracefully restarted"
		else
		    echo "$0 $ARG: httpd could not be restarted"
		    ERROR=7
		fi
	    else
		echo "$0 $ARG: configuration broken, ignoring restart"
		echo "$0 $ARG: (run 'apachectl configtest' for details)"
		ERROR=7
	    fi
	fi
        if [ $RUNNING2 -eq 0 ]; then
            echo "$0 $ARG: httpd2 not running, trying to start"
            if $HTTPD2 ; then
                echo "$0 $ARG: httpd2 started"
            else
                echo "$0 $ARG: httpd2 could not be started"
                ERROR2=5
            fi
        else
            if $HTTPD2 -t >/dev/null 2>&1; then
                if kill -USR1 $PID2 ; then
                    echo "$0 $ARG: httpd2 gracefully restarted"
                else
                    echo "$0 $ARG: httpd2 could not be restarted"
                    ERROR2=7
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR2=7
            fi
        fi
        if [ $RUNNING3 -eq 0 ]; then
            echo "$0 $ARG: httpd3 not running, trying to start"
            if $HTTPD3 ; then
                echo "$0 $ARG: httpd3 started"
            else
                echo "$0 $ARG: httpd3 could not be started"
                ERROR3=5
            fi
        else
            if $HTTPD3 -t >/dev/null 2>&1; then
                if kill -USR1 $PID3 ; then
                    echo "$0 $ARG: httpd3 gracefully restarted"
                else
                    echo "$0 $ARG: httpd3 could not be restarted"
                    ERROR3=7
                fi
            else
                echo "$0 $ARG: configuration broken, ignoring restart"
                echo "$0 $ARG: (run 'apachectl configtest' for details)"
                ERROR3=7
            fi
        fi
	;;
    status)
	case "`which $LYNXBIN`" in
		*"no "*) echo "Status doesn't work without lynx, try fullstatus" ;;
		*)  $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } ';;
	esac
        case "`which $LYNXBIN`" in
                *"no "*) echo "Status doesn't work without lynx, try fullstatus" ;;
                *)  $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } ';;
        esac
	;;
    fullstatus)
        case "`which $LYNXBIN`" in
                *"no "*) open $STATUSURL ;;
                *)  $LYNX $STATUSURL ;;
        esac
	;;
    configtest)
	if $HTTPD -t; then
	    :
	else
	    ERROR=8
	fi
        if $HTTPD2 -t; then
            :
        else
            ERROR2=8
        fi
        if $HTTPD3 -t; then
            :
        else
            ERROR3=8
        fi
	;;
    *)
	echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
	

So you noted that this file starts three Server-insances? Yepp. Currently I need PHP4 for some legacy-stuff (runs on port 8888), PHP5 for the current development (still runs on port 81) and for RT I needed another server instance as the PHP4-Module and the Perl-Module somehow did not want to work together. So that was the easiest way to fix that for me.

catColor

This plugin allows to add different colors and background-images to the categories of your favorite WordPress-Blog

Weiterlesen &rauqo;

Hello world!

So.

This is my first ‘real’ blog.

Let’s see, what it will bring.

I hope to find the time to write some stuff about the things I know. The chances are fair that it will include some words about PHP, Java, Gardening or Renovating our home.

Feel free to read and comment.