Posts Tagged ‘PHP’

php-trunk macport

macports is a widely used ports system for Mac OS. It’s repository contains hundreds of application that can be compiled and installed. The repository contains php 5.3. So if you want to run PHP from subversion you still have to compile it yourself and install it yourself outside your managed ports environment. I created a rather simple Portfile to build it from PHP’s trunk.

To use the php-trunk portsfile. Just extract the tarball into a directory and…

$ tar xzvf php-trunk-port.tar.gz
$ cd php-trunk-port
$ echo "file://`pwd`" > /opt/local/etc/macports/sources.conf
$ echo "file://`pwd`" >> /opt/local/etc/macports/sources.conf
$ port install php-trunk

And the best thing about the port: It compiles PHP with dtrace support :).

Please note the Portfile is very simple and is not tested with the additional modules provided by macports. So use it at your own risk and enhance it.

DOWNLOAD

UPDATE: as philip noted, it should be >> instead of >.

Writing a simple PHP sourcecode buildscript in Scala

Scala is a fascinating language. Running on the Java VM, Scala offers a powerful mixture from both the imperative Java world and functional programming including modern techniques like Actors. Personally I prefer to not just learn programming languages, but also try them out while reading through the book.

As I wanted to have nice a build system for my PHP subversion checkout, I used this need as a project to start coding Scala. So what do I exactly need? I want to build multiple versions of PHP from the same branch without checking out the code twice. I also want to configure these builds somewhere without always typing in the parameter list or so. For further versions I want to be able to configure these in a file that can easily be distributed to other machines.

I set down and wrote a parser for a configuration file that can configured build targets which is then build by
the program. The configuration file I used is specialized for this purpose, which is why I didn’t used something like ant or so. The result is called bauaffe-3.0.0a1.jar.

I’ll just show a few things done in the project, but mainly focus on what the nice script can do. Further blog posts will be about the actual implementation.

The configuration looks like this

$ cat ~/.buildmaker
begin default configuration
    define source "/Users/dsp/dev/c/php-src"
    define build "/Users/dsp/dev/c/php-src/build"
    define defaults as
        with "iconv=/opt/local"
    build trunk as
        "php60" using defaults
        "php60-debug" using defaults
            enable "debug"
    build branch "PHP_5_3" as
        "php53" using defaults
            environment PHP_AUTOCONF="autoconf213"
        "php53-debug" using defaults
            enable "debug"
            environment PHP_AUTOCONF="autoconf213"

.
Proper indention is not necessary (as e.g in python).


You might want to think that parsing the configuration file can be difficult. Well, if you use C you would use YACC, if you use PHP, I don’t know what you would have done, but Scala is made to create this kind of Domain Specific Languages (for my the config is a DSL). You can easily transform a EBNF directly to scala code using the JavaTokenParsers provided by the Scala Library. As an example this it the statement that parses the first line:

def begin : Parser[Configuration] =
"begin" ~ ("default" | stringLiteral) ~ "configuration" ~ rep(define | build) ^^ {
case "begin"~name~"configuration"~confs => new Configuration(name, confs)
}

which is directly taken from the BNF:

config ::= "begin" ( "default" | string ) "configuration" ( define | build )*

Did I mention that the actual parser is 170 lines of code with usual indention and formatting?


Configuration
The configuration file is searched in ~/.buildmaker, or if ~/.builmaker doesn’t exists, buildmaker.conf in the current directory. How do you configure the tool? First of all you can specify a configuration. It is usually called “default”. It is not yet supported to name it differently, although the parser is able to parse it. In further versions multiple configurations per file are allowed.

Variables
Variables are set using the define syntax. At the moment you can set the build and source variable as well the defaults variable, which is usually a block of statements that can be used in the branch configurations.

Branches
A branch is configured using the build syntax. You first have to specify which branch to build. Every branch can then configured to have build target with a given set of options. Branch options are:

  • with string: Builds the target with the given extension
  • enable string: Builds the target with the given extension
  • environment string=string: Builds the target with environment variable

. You can specify using defaults which will cause the runner to use the options specified in the defaults define.

At the moment the parser will not do a good job in notifying you what you are allowed to do and what not, although pure parse error will be emitted. You can also not set any other variable than the described once.

Building
Calling

$ java -jar bauaffe-3.0.0a1.jar list
TARGET                         LAST BUILD
php60                          None
php60-debug                    None
php53                          Sat Jan 09 16:55:12 CET 2010
php53-debug                    Sat Jan 09 16:59:37 CET 2010

gives you a list of parsed targets and their last build date. You can build a target using

$ java -jar bauaffe-3.0.0a1.jar 

or build all using

$ java -jar bauaffe-3.0.0a1.jar all

Please notice that the current version requires that you now what you are doing. You might miss some error messages or find them not useful. I’ll change this before the first release, if I’ll do a final version of it. I hope you like the little tool.

Download It!

Scala (pronounced /ˈskɑːlə, ˈskeɪlə/) is a multi-paradigm programming language designed to integrate features of object-oriented programming and functional programming.[1] The name Scala stands for “scalable language”, signifying that it is designed to grow with the demands of its users.

Calling Conventions – when you need to know C to understand PHP

I think most of the people using PHP wonder from time to time about particular behavior of the language. That’s pretty much the same case with every language. Pythoneers have their wtf moments, Ruby programmers have their wtf moments and C programmers tend to live in a whole wtf universe. But lately I stumbled over a nice one. It looked like a bug in PHP, but turns out to be an interesting, curious, part of the C-language. Imagine the following PHP code sample and note that $a and $b are not defined (yeah I know, it’s bad coding style..blabla..):

<?php
var_dump($a + $b);
?>

What is the expected result with error_reporting set to E_ALL?

PHP Notice: Undefined variable: b in /var/foo/bla on line 1
PHP Notice: Undefined variable: a in /var/foo/bla on line 1
.
Are you sure? I’m not. On x86 hardware b is fetched before a is fetched and therefore the executor detects that b is not set first. But wait. Let’s test this on a SPARC machine:

PHP Notice: Undefined variable: a in /var/foo/bla on line 1
PHP Notice: Undefined variable: b in /var/foo/bla on line 1
.
What? It evaluates it in the reversed oder? What is happening? So I spend a few minutes with my lovely debugger and it turns out that this is what happens in the engine (I use pseudo code here):

result ZEND_ADD_OPCODE()
{
   return add_function(get_op1(), get_op2());
}

Voila, that’s the problem. On SPARC get_op1() is executed before get_op2(), while it’s the other way round on x86. As get_opX() detects if a variable exists, the error messages appear in reversed oder. I did a little bit research (thank you SunCC Team for your answer!) and it turned out, that C99 doesn’t define the way function calls in parameter lists are executed. Therefore, every system and compiler is free to use it’s own ordering mechanism. My current plan: Write a compiler that does this by random(). The fix is trivial:

result ZEND_ADD_OPCODE()
{
  op2 = get_op2();
  return add_function(get_op1(), op2);
}

. It’s a lovely curiosity.

DTracing PHP

Dtrace is an extremely flexible and powerful tool to trace and debug applications. I recently dtraced PHP a little bit, so here is a tutorial how to start dtracing PHP.
(more…)

Compiling PHP under OpenSolaris

As I switched my main system recently from Linux to OpenSolaris I compiled PHP. Quiet obvious things are a little bit different on Solaris. The usual ./buildconf && ./configure && make install doesn’t work anymore. The good news: It’s not much harder. Let’s start to get the prequisites:
(more…)

Extension development on windows

When it comes to choose a operating system to run PHP applications often Linux is the choice. PHP, it’s buildsystem and it’s extensions are developed and optimized to run under Linux (and Unices). There are several reasons that Linux is the better supported operating system. Maybe due to historical reasons, maybe most of the core developers work und Linux (rumours were afloat that this is not quite true) or maybe just because the extensions finally run on a Linux server, so therefore it only counts if it runs under the target system.

This is actually the reason to not even try to compile my ktaglib extensions under Windows. Well but this approach is doomed to fail as most of the developers out there use Windows as their operating system. Therefore they are not able to run the extension and might not be able to ingerate your extension into their application. So actually I ended up booting up windows again (well after searching for the harddisk that contains a running windows) and try to compile it. Otherwise my fellow collegues wouldn’t be able to fix my buggy PHP code.

I remember compiling extensions under Windows a year ago, which actually doesn’t seems to be very easy for me. Since then a lot changed. Ongoing pecl2 efforts from Pierre with great help from Elizabeth and Rob now makes compiling on Windows without deeper knowledge about the Windows buildsystem easy. They carry together various notes about the build dependencies in the official php wiki. Furthermore Elizabeth recorded a video showing how to compile PHP on windows in a few minutes. So I actually ended up going to the pecl2.php.net page and just get the necessary libraries, put them into the right directory and compile PHP the same way as under Linux.

This helped to actually get ktaglib running under Windows. Just take the taglib windows port from the taglib website and compile your windows ktaglib using the PHP windows build system. Maybe the new scripts from the php-internals-win repository, that Pierre recently commited, help you to get you way through. It’s really amazing to concentrate on the work and not trying to get a buildsystem working.

ktaglib is a PHP binding for KDE’s taglib that helps you to read id3 tags and audio information from MP3s or OGGs. The current version is 0.0.1a1 and can be downloaded at http://pecl.php.net/package/KTaglib

getopt and longopts in PHP 5.3+

In the upcoming PHP 5.3+, the getopt() function will finally be available on Windows systems. Furthermore getopt() will support longopts on every system. To support this feature we moved the generic getopt function used by the PHP cli/cgi interpreter itself to main/ and recode getopt() to use this function.

Thanks for Jani to review and commit my patch.