YOUSEFUL / FILEMAKER
YsflPHP — function reference
Function prefix YsflPh_, 15 functions. Runs PHP from FileMaker through php.exe, either a
fresh process per call (process, the default) or a persistent worker (worker). PHP has no
embeddable SAPI on Windows, so mode=inproc is refused with a clear message.
php.exe is found through php=<path>, the YSFL_PHP environment variable, PATH, %ProgramFiles%\php,
C:\php, C:\xampp\php. The host script is written to %LOCALAPPDATA%\Youseful\hosts\ysflphp_host.php
and runs with display_errors off so nothing but the protocol reaches the pipe; warnings and notices
are converted to exceptions, so sloppy code fails loudly instead of silently.
Options (per call or via Configure)
mode=process|worker, timeout=<sec> (default 60), php=<path to php.exe>, param=<text>
(rest of the line; available as $fm_param).
Functions
| Function | Returns |
|---|---|
YsflPh_Run ( code ; {options} ) |
the value the code returns (arrays/objects as JSON, null → "", booleans true/false); when nothing is returned, what it echoed. A leading <?php and trailing ?> are tolerated |
YsflPh_RunFile ( path ; {options} ) |
same, from a .php file |
YsflPh_Call ( function ; {argsJSON} ; {options} ) |
calls a user or built-in function with a JSON array of arguments (worker mode for user functions) |
YsflPh_Set ( name ; value ; {type} ) |
defines a global; text (default), number, bool, json (associative arrays) |
YsflPh_Get ( name ) |
a global's value |
YsflPh_Output |
echoed output of the last call |
YsflPh_Error |
full error text with trace |
YsflPh_Reset |
clears user globals in the worker |
YsflPh_Stop |
ends the worker |
YsflPh_Configure ( options ) |
session defaults |
YsflPh_Mode |
effective mode, php.exe path, whether a worker is running |
YsflPh_Version |
plugin and php.exe path |
YsflPh_Register, YsflPh_LastError, YsflPh_LastErrorText |
Failures return ? ExceptionClass: message; YsflPh_Error has the trace.
Talking to FileMaker from the script
fm_evaluate ( $expr ), fm_sql ( $query ) (rows ¶, columns tab) and $fm_param work in both
modes; the calls travel through the plugin's pipe while the FileMaker call is in flight.
Set Variable [ $html ; YsflPh_Run ( "return nl2br(htmlspecialchars($fm_param));" ; "param=" & Notes::Body ) ]
Set Variable [ $r ; YsflPh_Configure ( "mode=worker" ) ]
Set Variable [ $r ; YsflPh_Run ( "function total($rows) { return array_sum(array_map(fn($r) => (float)explode(\"\t\", $r)[0], $rows)); }" ) ]
Set Variable [ $sum ; YsflPh_Call ( "total" ; JSONSetElement ( "[]" ; 0 ; fm_rows ; JSONArray ) ) ]