Coronium Cloud ERROR Call PHP function

Hi,

Chris

I Think i’m not doing wrong, but i am running an error. 

Thank you and I’m sorry.

rmoscat

TEST - 1

getdtrange.lua

local in_data = coronium.input()

local answer = coronium.php.run( ‘getdtrange’, in_data )

coronium.output( answer )

getdtrange.php

<?php

$in_data = json_decode(file_get_contents(‘php://input’));

function date_range($first, $last, $step = ‘+1 day’, $output_format = ‘d/m/Y’ ) {

    $dates = array();

    $current = strtotime($first);

    $last = strtotime($last);

    $key = 1;

    while( $current <= $last ) {

        $varkey = (string) $key;

        $dates[$varkey] = date($output_format, $current) . ’ - ’ . date($output_format, strtotime($step, $current));

        $current = strtotime($step, $current);

        $key++;

    }

    return $dates;

}

$dates = date_range(“2014-01-01”, “2014-01-08”, “+1 day”, “mdY”);

$response = $dates;

print(json_encode($response));

?>

This is the error I get

ERROR -->  

error: Expected value but found invalid token at character 1

errorCode: -2

TEST - 2

getdtrange.php

<?php

$in_data = json_decode(file_get_contents(‘php://input’));

$keyvalues = array();

$keyvalues[“1”] = “bar”;

$keyvalues[“2”] = “power”;

$keyvalues[“3”] = “power”;

$keyvalues[“4”] = “power”;

$response = $keyvalues;

print(json_encode($response));

?>

NOT ERROR 

result:

   1: bar

   2: power

   3: power

   4: power

Hi,

From your test, it looks like something is not able to be encoded to JSON correctly in the PHP code. 

What is the type of the   $dates variable?

Cheers.

Hello!

The variable $date is an array.

I have been doing several tests, when the length of the string gets bigger than a limit it gives me an error. For example: 

This kind of example generates an error

<?php

$in_data = json_decode(file_get_contents(‘php://input’));

 

$keyvalues = array();

$keyvalues[“1”] = “bar”;

$keyvalues[“2”] = " Expected value but found invalid token at character.ERROR";

$keyvalues[“3”] = “power”;

$keyvalues[“4”] = “power”;

 

$response = $keyvalues;

 

print(json_encode($response));

?>

 

Cordially, 

 Rmoscat

Hi,

From your test, it looks like something is not able to be encoded to JSON correctly in the PHP code. 

What is the type of the   $dates variable?

Cheers.

Hello!

The variable $date is an array.

I have been doing several tests, when the length of the string gets bigger than a limit it gives me an error. For example: 

This kind of example generates an error

<?php

$in_data = json_decode(file_get_contents(‘php://input’));

 

$keyvalues = array();

$keyvalues[“1”] = “bar”;

$keyvalues[“2”] = " Expected value but found invalid token at character.ERROR";

$keyvalues[“3”] = “power”;

$keyvalues[“4”] = “power”;

 

$response = $keyvalues;

 

print(json_encode($response));

?>

 

Cordially, 

 Rmoscat