purefan Posted August 1, 2007 Share Posted August 1, 2007 Hello everyone! First post here and its a question, bommer. Well I need to have a system do a remote insert on a database, every X action the system would do this insert. Since the implementation could change we decided to host the actual function that does the insert in a remote server, and the client system would fetch this function and use it. My approach was to fetch the code into a variable, create the function there with create_function and then just use it, it does work except for the parameters passed to the new function are not being taken into account by the code in the function. So, there are inserts in the database, but with empty values. Here is how I am building the function in the client system: // remPath is defined elsewhere $remFile = $this->readRemoteFile($remPath); // now $remFile has the code in the form of not-a-function but using variables // now I create the function $doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt',$remFile); // as you can see there are several variables, that are used in the code for the function in $remFile // this is probably where I am wrong // then I know the code is being executed properly because in the code for the function // there is a check for the parameters to see if they are empty, this check is working // on this line (me trying to call the function) $doRemLog($thisIp,$license,$currUrl,$comment,"1"); Could any of you wise guys help me debug this? in short, the function is being created and it works, the parameters used in the function are always being used as empty. I did check, and they are not empty. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/62841-execute-a-remote-function-for-inserts-in-db/ Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 What do you get when you run this: $remFile = <<<EOF echo '<pre>' . print_r(func_get_args(), 1) . '</pre>'; EOF; $doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt', $remFile); $doRemLog($thisIp, $license, $currUrl, $comment, 1); You should get an array printed out showing you what each parameter is set to. What result do you get Quote Link to comment https://forums.phpfreaks.com/topic/62841-execute-a-remote-function-for-inserts-in-db/#findComment-312845 Share on other sites More sharing options...
purefan Posted August 1, 2007 Author Share Posted August 1, 2007 Hello WildTeen, I copy pasted it and im getting an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING looked for it and found nothing funky... left some extra spaces for the heredoc but wasnt it... Quote Link to comment https://forums.phpfreaks.com/topic/62841-execute-a-remote-function-for-inserts-in-db/#findComment-312851 Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 I don't think its my code snippet causing that error. For me it is error free. I'm not sure. Its works fine for me with some dummy data: <?php $thisIp = '127.0.0.1'; $license = 'bla'; $currUrl = 'Unkown'; $comment = 'ohhh!'; $remFile = <<<EOF echo '<pre>' . print_r(func_get_args(), 1) . '</pre>'; EOF; $doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt', $remFile); $doRemLog($thisIp, $license, $currUrl, $comment, 1); ?> I get this result: Array ( [0] => 127.0.0.1 [1] => bla [2] => Unkown [3] => ohhh! [4] => 1 ) Quote Link to comment https://forums.phpfreaks.com/topic/62841-execute-a-remote-function-for-inserts-in-db/#findComment-312995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.