I'm forced to use a legacy PHP module (wrapper for an external API that has NO documentation at all) in my node application.
I'm trying to pass a small chunk of data to my PHP script via command line arguments like:
var spawn = require('child_process').spawn;
//...
//later on:
var LegacyScript = spawn('php', ['bridge.php', JSON.stringify(someData)]);
In my bridge.php
I am doing the following:
<?php
$data = json_decode($argv[1], TRUE);
# this logs the data just fine - i can use the string and lint it / parse it - everything perfect
file_put_contents('phpgot.txt', $argv[1]);
# this is empty
file_put_contents('phpprocessed.txt', $data);
# this is NULL
file_put_contents('phpreencoded.txt', json_encode($data));
# my node module gets plain null
echo json_encode($data);
?>
Is the approach I am taking valid at all? I am a little puzzled as the data seems to arrive just fine inside my PHP bridge, but it will fail at parsing it although it is perfectly valid JSON that passes jsonlint
and the likes.
Is there another (more elegant) way of passing data to the spawned process?
EDIT : So I just noticed this is only failing when there are special characters (ü,ö,ä and the like) present in the JSON string. When the content is plain latin charset it works just as expected. I'm in a all UTF-8 environment though.