Compdigitec Labs

Using UTF-8 in PHP-GTK2

By admin | August 18, 2008

An image of PHP-GTK2 on Ubuntu trying to display Asian languages
When trying to use a string that has characters that are non-English (Asian and middle east characters) or characters that have accents for PHP-GTK’s widgets, you may possibly encounter a situation like the image to the right.

This bug or glitch is caused by the fact that you are trying to use a regional encoding for the application, when in fact you should be passing utf8_encode‘ed strings to it. This also happens with non-english characters in an Gettext messages file.

This can be accomplished with:

<?php
// ... code

// Instead of using function($nonenglish), use function(utf8_encode($nonenglish)) instead
echo(utf8_encode(file_get_contents($argv[1])));

// … code
?>

The example above outputs the contents of the first parameter. You can use the above script to encode message.mo files with php filename.php message.mo > message.mo – though you should consider making a backup.

For displaying text inside GtkTextView (set text via GtkTextBuffer) though, you will need to use iconv to convert the regional encoding to UTF-8:


<?php
// ... code

// For conversion from Windows Notepad
echo iconv(“windows-1252”,“UTF-8”,$str);
// For conversion from French
echo iconv(“IBM863”,“UTF-8”,$str);
// For conversion from Chinese
echo iconv(“GB2312”,“UTF-8”,$str);

// … code
?>

If you found this article helpful, please help Compdigitec spread the word or please leave a comment. Don’t forget to subscribe for more interesting articles!

Topics: PHP | 11 Comments »

Changing the application name of a GtkAboutDialog in PHP-GTK2

By admin | August 17, 2008

For those of you who have never heard of it, a GtkAboutDialog is a convience GtkDialog to display application credits. However, the documentation (archive at 2008-08-17) for it does not specify a way to change the application’s name, and as a result ends up using the script name for the application, which is very ugly and unprofessional.

To change the application name, use the undocumented function GtkAboutDialog::set_name() to change the name. Here is an example:


<?php
$dialog
= new GtkAboutDialog();
$copy = "(C) Copyright 2008 Example.";
$license = "GNU GPL Text would go here";
$web = "http://www.example.com/";
$version = "Version 1.0";
$prog = "YourExampleProg";
$desc = "A sample program to demonstrate the use of GtkAboutDialog";
$dialog->set_copyright($copy);
$dialog->set_license($license);
$dialog->set_website($web);
$dialog->set_version($version);
$dialog->set_name($prog); // Use this line to set app name
$dialog->set_comments($desc);
$dialog->run();
$dialog->hide();
?>

If you found this article helpful or useful, please help Compdigitec spread the word or leave a comment. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: PHP | 9 Comments »

Stopping the “PHP Fatal error: Internal object missing in” error in PHP-GTK2

By admin | August 16, 2008

In PHP-GTK2, if you build your own class of an existing PHP-GTK2 class, you may encounter one of the following errors:

This is somehow (not documented) caused by not calling parent::__construct(), the parent constructor. For example, try to run the following snippet:
<?php
if (!class_exists(‘gtk’)) {
die(
“ERROR: No PHP-GTK2 Module.\n”);
}

class Myclassw extends GtkWindow {
protected $label;

function __construct() {
$label = new GtkLabel(“Hello World – will fail”);
$this
->add($label);

$this->show();
$this->show_all();

Gtk::main();
}
}
$a = new Myclassw();
?>
You should receive the following errors: (path may be different)

Now, try this snippet:

<?php
if (!class_exists('gtk')) {
die(
"ERROR: No PHP-GTK2 Module.\n");
}
class
Myclassw extends GtkWindow {
protected
$label;

function __construct() {
parent::__construct(); // New line inserted here

$label = new GtkLabel(“Hello World – will work!”);
$this->add($label);
$this->show();
$this->show_all();
Gtk::main();
}
}
$a = new Myclassw();
?>
Now this time, it should work as expected. If you encounter “ERROR: No PHP-GTK2 module.”, this means that you are either running it in your web server or ran it without php-gtk2.(so/dll) in your php.ini.

All tests were ran on Ubuntu Linux 8.04, PHP 5.2.4-2ubuntu5.3 and Linux kernel version 2.6.24-19-generic. If this article helped you solve the problem, please help us spread the word or please leave a comment. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux, PHP, Windows | 8 Comments »

Embeder – a free PHP to EXE solution

By admin | August 15, 2008

If you’re looking for a PHP to EXE solution that supports PHP5, Embeder is one rarely mentioned application that will convert your PHP applications into a Windows executable file, although it will only work with PHP 5.0.3. Below are the steps to set it up on your system. (Will run under Linux with Wine, too.)

  1. Download embeder and it’s php-embed.ini.
  2. Download PHP and php_win32std.dll. (Do not use the PHP binary provided on php.net)
  3. Extract PHP to a directory (preferably short with no spaces). Put embeder.exe and php-embed.ini inside the directory.
  4. Put php_win32std.dll inside the ext directory.
  5. Add the directory to your PATH.
  6. You’re done! To test it, compile the following test program (save as test.php):
    <?php
    echo "Testing...\r\n";
    ?>

    Run these commands to make test.exe:
    Windows:
    embeder new test
    embeder main test test.php
    Linux:
    wine embeder.exe new test
    wine embeder.exe main test test.php

Notes:

  1. If you are using Wine, you can safely ignore these messages:
    fixme:msvcrt:MSVCRT__sopen : pmode 0x01b6 ignored
    fixme:advapi:DeregisterEventSource ((nil)) stub
  2. (Wine users only) If you experience the crash wine: Unhandled page fault on read access to 0x00000000 at address 0x100c5619 (thread 0009), starting debugger…, it means that you are not using PHP 5.0.3. See full log for details.
  3. (Windows users only) If you experience the following crash dialog, it also means that you are not using PHP 5.0.3.
    Embeder Crashing on Windows XP with PHP 5.2.6

So as you can see, Embeder is an good solution to use for PHP to EXE or php2exe problems. You can even combine it with bcompiler to create commercial software. If you found this article or guide useful, please help us spread the word or leave a comment. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

Topics: Linux, PHP, Windows | 23 Comments »

How to use dd to copy, move and erase disks

By admin | August 14, 2008

Often, you may encounter the need to move a partition, copy a partition or copy a CD/DVD. The easiest and most user-friendly way to do this is with GParted. However, in a server environment or a command line environment where the GUI is not available, GNU dd is an good way to perform these simple tasks. Here are easy tips on how to use dd for disk manipulation. Most of these commands require you to be part of the “disk” group.

If you are on the Windows platform, you will need a copy of rawwrite dd for Windows in your %PATH%. To list the disks with rawwrite dd, use dd –list and use the devices listed there; for example, use “\\?\Device\HarddiskVolume1” instead of “/dev/sda1”. For CD drives, replace /dev/cdrom with “\\?\Device\CdRom0”.

  1. dd if=/dev/partition of=/dev/destination – Copy the partition partition to the partition destination.
  2. dd if=/dev/cdrom of=filename.iso – Make an ISO image of the disc in your CD drive as filename.iso. Then you can use in Virtual Machines such as VMWare, mount it in Windows with DaemonTools or mount it as an file system in Linux.
  3. dd something bs=speed – Performs the action something at the speed of speed bytes per second. Can be used to copy CDs and disks faster.
  4. dd if=/dev/zero of=/dev/pdest – Wipes the filesystem from the partition pdest, which can you can then make a new filesystem with mkfs.ext3 /dev/pdest.
  5. dd if=/dev/part of=filename.disk – Makes a intact backup of everything on the partition part into the file filename.disk.
  6. dd if=filename.disk of=/dev/part – Copies from intact backup filename.disk into the partition part. Make sure that the partition part is big enough to hold filename.disk.
  7. dd if=/dev/cdrom of=/dev/part bs=10M – Copies the CD filesystem on your CD to the partition part.
  8. dd if=/dev/fd0 of=filename.img – Copies the floppy in your floppy drive to filename.img. Then the image can be used in Virtual Machines.
  9. dd if=filename.img of=/dev/fd0 – Copies the image filename.img to the floppy in your floppy drive.
  10. dd if=/dev/disk of=bootsect.bin bs=512 count=1 – Copies the boot sector of disk disk to the file bootsect.bin.
  11. dd if=/dev/disk of=/dev/null – The best way to waste your CPU power; copies disk to NULL.

So as you can see, dd is a very useful tool to manipulate partitions and images. If you found this article interesting or helpful, please help us spread the word or please leave a comment!

Topics: Linux, Windows | 7 Comments »

Parsing text files in PHP with FlatfileTools

By admin | August 13, 2008

Compdigitec FlatfileTools is a API written in PHP to manipulate, read and modify plain text databases. It can also manipulate existing databases, such as CSV files. It is released under the GNU General Public License and therefore is free software.

To use it, download Compdigitec FlatfileTools. Then include_once it like this:

<?php

include_once(‘flatfiletools.lib.php’);

// The rest of your code goes here…

?>

For example, to parse the following CSV file – name it testdb.csv. Make sure there is no extra newline at the bottom. (UNIX line endings. To parse Windows/DOS line endings, change line in config.ini to “\r\n”). Do not forget to change config.ini’s div setting to “,”:

Software,License
Linux,GPL
Mozilla Firefox,GPL+LGPL+MPL
Compdigitec FlatfileTools,GPL

Use the following code:


<?php
// Include flatfiletools
include_once('flatfiletools.lib.php');
// Create new db and set file
$f = new FlatfileTools();
$f->set_datafile('testdb.csv');
// Populate - WARNING: Due to a bug in FlatfileTools v1.0, true means failure and false means success in this function.
if($f->populate()) {
    echo 
"An error happened on line 8 during a call to populate().\n";
};
// Get number of lines
$lines $f->get_number_of_lines();
// Output table header
echo "<table border=\"1\">";
// Until the last line get line
for($i 0$i <= $lines$i++) {
    
$var $f->get_line($i);
    if(
$var === false) {
        echo 
"An error happened on line 16 during a call to get_line() - Current Row Number is $i. \n";
    } else {
        echo 
"<tr>";
        if(
$i == 0) {
            foreach(
$var as $val) {
                echo 
"<th>$val</th>";
            }
        } else {
            foreach(
$var as $val) {
                echo 
"<td>$val</td>";
            }
        };
        echo 
"</tr>";
    };
}
// Output footer
echo "</table>";
?>


If you run this code and receive the error “An error happened on line 16 during a call to get_line() – Current Row Number is 5. ” , it’s because your CSV file has an extra newline at the bottom of it. You can supress this error by commenting out the error on line 18.

So as you can see, Compdigitec FlatfileTools is an powerful API to manipulate, parse and read flat text files in PHP. The example above could have easily been customized to manipulate tab delimited text files by changing config.ini’s div to “\t” instead. You can also write to text files with this API – read the full documentation for more details.

If you found this article interesting, please help us spread the word or please leave a comment. You can also subscribe to Compdigitec Labs via RSS.

Topics: Internet, Linux, PHP, Windows | 7 Comments »

Create and extract tarballs in Windows

By admin | August 12, 2008

For those of you who want to extract and create tarballs (tgz, tbz) on the Windows platform, there are many commercial tools to extract tarballs. If you want an graphical app, you can use the open-source 7-zip archiver for Windows.

However, there are also not many tools extract tarballs from the command line (cmd.exe or command.com). Below are easy steps to install a GNU Tar-like program (bsdtar) to use in the command line. BSDtar is licensed under the BSD License (as specified here).

  1. Download bsdtar and extract to a directory, preferably without spaces.
  2. Go into Control Panel -> System and click on “Advanced”. Then click on “Environmental Variables”.
    Screenshot of the Advanced tab
  3. In the user variables section, add the path you extracted bsdtar to the PATH variable. If the PATH variable has not been created, create it.
  4. You’re done! To test it, type tar zcvf archive.tar.gz * to create a tarball (tar+gzip) of all the files in the current directory.

If you found this article helpful or interesting, please leave a comment or help us spread the word!

Topics: Windows | 10 Comments »

Install bcompiler for PHP on Ubuntu Linux

By admin | August 10, 2008

The PHP bytecode compiler is a useful way to convert PHP to bytecode, which can then be converted to binaries. However, the Ubuntu packaging team has not yet made a binary package of bcompiler available. However, you can install this bytecode compiler yourself with these 9 easy to follow steps. A binary build is availible, but you should try to compile/install it yourself because the binary extension might not be suitable for your computer.

  1. Install the basic dependencies with sudo apt-get install automake m4 php5-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following extra packages will be installed:
    autoconf automake1.4 autotools-dev libtool shtool
    Suggested packages:
    autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc gfortran fortran95-compiler libtool-doc
    Recommended packages:
    automaken libltdl3-dev
    The following NEW packages will be installed:
    autoconf automake automake1.4 autotools-dev libtool m4 php5-dev shtool
    0 upgraded, 8 newly installed, 0 to remove and 67 not upgraded.
    Need to get 2371kB of archives.
    After this operation, 9540kB of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Get:1 http://us.archive.ubuntu.com hardy/main m4 1.4.10-1 [207kB]
    Get:2 http://us.archive.ubuntu.com hardy/main autoconf 2.61-4 [448kB]
    Get:3 http://us.archive.ubuntu.com hardy/main autotools-dev 20070725.1 [61.9kB]
    Get:4 http://us.archive.ubuntu.com hardy/main automake 1:1.10.1-2 [519kB]
    Get:5 http://us.archive.ubuntu.com hardy/main automake1.4 1:1.4-p6-12 [272kB]
    Get:6 http://us.archive.ubuntu.com hardy/main libtool 1.5.26-1ubuntu1 [340kB]
    Get:7 http://us.archive.ubuntu.com hardy/main shtool 2.0.7-1 [159kB]
    Get:8 http://us.archive.ubuntu.com hardy-updates/main php5-dev 5.2.4-2ubuntu5.3 [364kB]
    Fetched 2371kB in 32s (72.5kB/s)
    Selecting previously deselected package m4.
    (Reading database ... 123151 files and directories currently installed.)
    Unpacking m4 (from .../archives/m4_1.4.10-1_i386.deb) ...
    Selecting previously deselected package autoconf.
    Unpacking autoconf (from .../autoconf_2.61-4_all.deb) ...
    Selecting previously deselected package autotools-dev.
    Unpacking autotools-dev (from .../autotools-dev_20070725.1_all.deb) ...
    Selecting previously deselected package automake.
    Unpacking automake (from .../automake_1%3a1.10.1-2_all.deb) ...
    Selecting previously deselected package automake1.4.
    Unpacking automake1.4 (from .../automake1.4_1%3a1.4-p6-12_all.deb) ...
    Selecting previously deselected package libtool.
    Unpacking libtool (from .../libtool_1.5.26-1ubuntu1_i386.deb) ...
    Selecting previously deselected package shtool.
    Unpacking shtool (from .../shtool_2.0.7-1_all.deb) ...
    Selecting previously deselected package php5-dev.
    Unpacking php5-dev (from .../php5-dev_5.2.4-2ubuntu5.3_i386.deb) ...
    Setting up m4 (1.4.10-1) ...

    Setting up autoconf (2.61-4) …

    Setting up autotools-dev (20070725.1) …
    Setting up automake (1:1.10.1-2) …

    Setting up automake1.4 (1:1.4-p6-12) …

    Setting up libtool (1.5.26-1ubuntu1) …
    Setting up shtool (2.0.7-1) …
    Setting up php5-dev (5.2.4-2ubuntu5.3) …

  2. Then, install the secondary dependencies with sudo apt-get install re2c libbz2-dev:
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
    libbz2-dev re2c
    0 upgraded, 2 newly installed, 0 to remove and 67 not upgraded.
    Need to get 219kB of archives.
    After this operation, 582kB of additional disk space will be used.
    Get:1 http://us.archive.ubuntu.com hardy/main libbz2-dev 1.0.4-2ubuntu4 [32.1kB]
    Get:2 http://us.archive.ubuntu.com hardy/main re2c 0.12.1-1build1 [187kB]
    Fetched 219kB in 1s (113kB/s)
    Selecting previously deselected package libbz2-dev.
    (Reading database ... 123871 files and directories currently installed.)
    Unpacking libbz2-dev (from .../libbz2-dev_1.0.4-2ubuntu4_i386.deb) ...
    Selecting previously deselected package re2c.
    Unpacking re2c (from .../re2c_0.12.1-1build1_i386.deb) ...
    Setting up libbz2-dev (1.0.4-2ubuntu4) ...
    Setting up re2c (0.12.1-1build1) ...
  3. Compile and install bcompiler with sudo pecl install bcompiler-0.8:
    downloading bcompiler-0.8.tgz ...
    Starting to download bcompiler-0.8.tgz (46,667 bytes)
    .............done: 46,667 bytes
    10 source files, building
    running: phpize
    Configuring for:
    PHP Api Version: 20041225
    Zend Module Api No: 20060613
    Zend Extension Api No: 220060519
    building in /var/tmp/pear-build-root/bcompiler-0.8
    running: /tmp/pear/cache/bcompiler-0.8/configure
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for a sed that does not truncate output... /bin/sed
    checking for gcc... gcc
    checking for C compiler default output file name... a.out
    checking whether the C compiler works... yes
    checking whether we are cross compiling... no
    checking for suffix of executables...
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking whether gcc and cc understand -c and -o together... yes
    checking for system library directory... lib
    checking if compiler supports -R... no
    checking if compiler supports -Wl,-rpath,... yes
    checking build system type... i686-pc-linux-gnu
    checking host system type... i686-pc-linux-gnu
    checking target system type... i686-pc-linux-gnu
    checking for PHP prefix... /usr
    checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
    checking for PHP extension directory... /usr/lib/php5/20060613+lfs
    checking for PHP installed headers prefix... /usr/include/php5
    checking for re2c... re2c
    checking for re2c version... 0.12.1 (ok)
    checking for gawk... gawk
    checking whether to enable bcompiler support... yes, shared
    checking for BZip2 in default path... found in /usr
    checking for BZ2_bzerror in -lbz2... yes
    checking for ld used by gcc... /usr/bin/ld
    checking if the linker (/usr/bin/ld) is GNU ld... yes
    checking for /usr/bin/ld option to reload object files... -r
    checking for BSD-compatible nm... /usr/bin/nm -B
    checking whether ln -s works... yes
    checking how to recognize dependent libraries... pass_all
    checking how to run the C preprocessor... gcc -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking dlfcn.h usability... yes
    checking dlfcn.h presence... yes
    checking for dlfcn.h... yes
    checking for g77... no
    checking for xlf... no
    checking for f77... no
    checking for frt... no
    checking for pgf77... no
    checking for cf77... no
    checking for fort77... no
    checking for fl32... no
    checking for af77... no
    checking for xlf90... no
    checking for f90... no
    checking for pgf90... no
    checking for pghpf... no
    checking for epcf90... no
    checking for gfortran... no
    checking for g95... no
    checking for xlf95... no
    checking for f95... no
    checking for fort... no
    checking for ifort... no
    checking for ifc... no
    checking for efc... no
    checking for pgf95... no
    checking for lf95... no
    checking for ftn... no
    checking whether we are using the GNU Fortran 77 compiler... no
    checking whether accepts -g... no
    checking the maximum length of command line arguments... 98304
    checking command to parse /usr/bin/nm -B output from gcc object... ok
    checking for objdir... .libs
    checking for ar... ar
    checking for ranlib... ranlib
    checking for strip... strip
    checking if gcc supports -fno-rtti -fno-exceptions... no
    checking for gcc option to produce PIC... -fPIC
    checking if gcc PIC flag -fPIC works... yes
    checking if gcc static flag -static works... yes
    checking if gcc supports -c -o file.o... yes
    checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
    checking whether -lc should be explicitly linked in... no
    checking dynamic linker characteristics... GNU/Linux ld.so
    checking how to hardcode library paths into programs... immediate
    checking whether stripping libraries is possible... yes
    checking if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... no
    configure: creating libtool
    appending configuration tag "CXX" to libtool
    appending configuration tag "F77" to libtool
    configure: creating ./config.status
    config.status: creating config.h
    running: make
    /bin/bash /var/tmp/pear-build-root/bcompiler-0.8/libtool --mode=compile gcc -I. -I/tmp/pear/cache/bcompiler-0.8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/bcompiler-0.8/include -I/var/tmp/pear-build-root/bcompiler-0.8/main -I/tmp/pear/cache/bcompiler-0.8 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/bcompiler-0.8/bcompiler.c -o bcompiler.lo
    mkdir .libs
    gcc -I. -I/tmp/pear/cache/bcompiler-0.8 -DPHP_ATOM_INC -I/var/tmp/pear-build-root/bcompiler-0.8/include -I/var/tmp/pear-build-root/bcompiler-0.8/main -I/tmp/pear/cache/bcompiler-0.8 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/cache/bcompiler-0.8/bcompiler.c -fPIC -DPIC -o .libs/bcompiler.o
    /tmp/pear/cache/bcompiler-0.8/bcompiler.c:1342:8: warning: extra tokens at end of #endif directive
    /bin/bash /var/tmp/pear-build-root/bcompiler-0.8/libtool --mode=link gcc -DPHP_ATOM_INC -I/var/tmp/pear-build-root/bcompiler-0.8/include -I/var/tmp/pear-build-root/bcompiler-0.8/main -I/tmp/pear/cache/bcompiler-0.8 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -o bcompiler.la -export-dynamic -avoid-version -prefer-pic -module -rpath /var/tmp/pear-build-root/bcompiler-0.8/modules bcompiler.lo -lbz2
    gcc -shared .libs/bcompiler.o -lbz2 -Wl,-soname -Wl,bcompiler.so -o .libs/bcompiler.so
    creating bcompiler.la
    (cd .libs && rm -f bcompiler.la && ln -s ../bcompiler.la bcompiler.la)
    /bin/bash /var/tmp/pear-build-root/bcompiler-0.8/libtool --mode=install cp ./bcompiler.la /var/tmp/pear-build-root/bcompiler-0.8/modules
    cp ./.libs/bcompiler.so /var/tmp/pear-build-root/bcompiler-0.8/modules/bcompiler.so
    cp ./.libs/bcompiler.lai /var/tmp/pear-build-root/bcompiler-0.8/modules/bcompiler.la
    PATH="$PATH:/sbin" ldconfig -n /var/tmp/pear-build-root/bcompiler-0.8/modules
    ----------------------------------------------------------------------
    Libraries have been installed in:
    /var/tmp/pear-build-root/bcompiler-0.8/modules

    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR’
    flag during linking and do at least one of the following:
    – add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
    during execution
    – add LIBDIR to the `LD_RUN_PATH’ environment variable
    during linking
    – use the `-Wl,–rpath -Wl,LIBDIR’ linker flag
    – have your system administrator add LIBDIR to `/etc/ld.so.conf’

    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ———————————————————————-

    Build complete.
    Don’t forget to run ‘make test’.

    running: make INSTALL_ROOT=”/var/tmp/pear-build-root/install-bcompiler-0.8″ install
    Installing shared extensions: /var/tmp/pear-build-root/install-bcompiler-0.8/usr/lib/php5/20060613+lfs/
    running: find “/var/tmp/pear-build-root/install-bcompiler-0.8” -ls
    191629 4 drwxr-xr-x 3 root root 4096 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8
    191686 4 drwxr-xr-x 3 root root 4096 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8/usr
    191687 4 drwxr-xr-x 3 root root 4096 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8/usr/lib
    191688 4 drwxr-xr-x 3 root root 4096 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8/usr/lib/php5
    191689 4 drwxr-xr-x 2 root root 4096 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8/usr/lib/php5/20060613+lfs
    191685 124 -rwxr-xr-x 1 root root 119116 Aug 10 12:20 /var/tmp/pear-build-root/install-bcompiler-0.8/usr/lib/php5/20060613+lfs/bcompiler.so

    Build process completed successfully
    Installing ‘/usr/lib/php5/20060613+lfs/bcompiler.so’
    install ok: channel://pear.php.net/bcompiler-0.8

  4. If you encounter “ERROR: `phpize’ failed“, that means you have not yet installed php5-dev. Repeat step 1 then try again.
  5. If you encounter “configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers“, repeat step 2 to install re2c.
  6. If you encounter “checking for BZip2 in default path… not found” or “configure: error: Please reinstall the BZip2 distribution“, repeat step 2 to install libbz2-dev.
  7. Add “extension=bcompiler.so” to /etc/php5/cli/php.ini to activate the extension.
  8. You’re done! To test it, save the following file as example.php:
    <?php
    /**
    * A function to output hello world
    *
    * @function helloWorld
    * @return void
    */
    function helloWorld() {
    echo "Hello World!\n";
    }
    ?>

    Save the following as compile.php:

    <?php
    $fh = fopen("example.phb", "w");
    bcompiler_write_header($fh);
    bcompiler_write_file($fh, "example.php");
    bcompiler_write_footer($fh);
    fclose($fh);
    ?>

    And save this one as use_p.php:

    <?php
    include_once('example.phb');
    helloWorld();
    helloWorld();
    helloWorld();
    ?>

    Now run compile.php to compile it. Then run use_p.php – you should see “Hello World!” three times. If you do, you’re done!

  9. If for any reason your computer cannot compile bcompiler.so, here is a binary build just in case. Do not forget to test it using the step above!

If this guide or article was helpful, please help us spread the word!

Topics: Linux, PHP | 4 Comments »

Simple way to read bzip2 compressed files in PHP

By admin | August 9, 2008

If you are looking for a way to read quick way to read a compressed bzip2 file’s contents, look no further. We have made a function that works similar to the way file_get_contents works.

The code is released under the GPL v2 or later license.

<?php
/**
* Reads an uncompressed file from a bzip2 file
*
* @function file_bzip2_contents
* @author Compdigitec - http://www.compdigitec.com/
* @copyright (C)Copyright 2008 Compdigitec. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt
* @param string $filename The filename of the bz2 compressed file
* @param resource $res An existing resource opened by bzopen
* @return string The contents of the bzip2 file
*/

function file_bzip2_contents($filename,$res = null) {
$file = strval($filename); // Avoid bad input
if($res === null) {
$res = bzopen($filename,'r');
$a = '1qza';
};
$contents = bzread($res);
if($a == "1qza") {
bzclose($res);
}
return $contents;
}

?>

Topics: PHP | 6 Comments »

Unofficial Bigloo 3.1a Build for Windows

By admin | August 1, 2008

If you’re looking for a prebuilt build of Bigloo 3.1a, you’re in luck! We have made a Bigloo 3.1a build for Windows, ready to be installed and in various formats. You can download the builds here . Bigloo 3.1a is required to build Roadsend PHP for Windows.

If you want to compile Bigloo 3.1a yourself though, follow these steps:

  1. Install Cygwin (http://www.cygwin.com). Make sure you select the gcc-core, gcc-g++ and make packages.
  2. Download the bigloo 3.1a sources (http://www-sop.inria.fr/mimosa/fp/Bigloo/) and extract to ~/bigloo-3.1a
  3. Start the Cygwin shell and change into the bigloo directory with "cd bigloo-3.1a".
  4. Configure bigloo: "./configure –prefix=/bigloo". Here are the configure logs of a successful compile.
  5. Wait for it to finish.
  6. Type "make". Here are the make logs of a successful compile.
  7. Wait again for it to finish.
  8. Type "make install". Here are the make install logs of a successful compile.
  9. You’re done! Bigloo 3.1a is in /bigloo.

Download Bigloo 3.1a for Windows

Topics: PHP, Windows | 15 Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! « Older Entries Newer Entries »