For quite a while, the documentation and product information for bBox has mentioned it as a way to run PHP scripts, but I only just recently realized that we never had any examples of how to do this.
Here are two methods to try.
Both of these examples assume that you will store the scripts in a FileMaker field. Why not just include the PHP script as part of the Set Variable or a Set Field calculation? If you do, you’ll hit a number of headaches dealing with things like nested quotes, escaping control characters, or other issues that make it problematic.
If you don’t already have the bBox plug-in, download it here.
Shell & Here Document
For our first try at this, we’ll use something called a shell here document, which is a convenient method of creating an arbitrary chunk of text in the shell.
Here’s the hybrid shell and PHP script to store in your FileMaker field:
php <<CodeBlock <?php Print \"Starting PHP script now\n\n\"; phpinfo(); Print \"\nPHP script now done\"; ?>
To run the script we execute this function call inside of a Set Variable or Set Field Script step:
bBox_Shell ( 0; SCRIPTS::script_text )
And this returns the following result back to FileMaker:
Starting PHP script now phpinfo() PHP Version => 5.5.29 System => Darwin sibrMac 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64 Build Date => Sep 9 2015 00:14:30 ... PHP script now done
Script by Parameter
If you want to create a subroutine for executing arbitrary PHP scripts, this version may be slightly better.
First we need a field with the PHP code in it:
<?php Print "Starting PHP script now\n\n"; phpinfo(); Print "\nPHP script now done"; ?>
Then we use the function call below to execute a very short shell script, passing the PHP script in as a parameter:
bBox_Bash ( 0; "echo $1 | php"; "-s"; SCRIPTS::script_text )
This should return the same result as our previous example.
For both examples, if running it server-side, you may need to specify the full path to the php command. For the standard Mac OS install it can be found at /usr/bin/php
Simon
One thought on “Run PHP code with FileMaker & bBox”