Xu Wei Jie Posted February 25, 2009 Share Posted February 25, 2009 system("php $frame $new_id > src/$output_dir/$output", $retval); what does this function do? Any help would be appreciated . Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/ Share on other sites More sharing options...
Maq Posted February 25, 2009 Share Posted February 25, 2009 Not knowing what the values of the variables, it's kind of hard to tell. Looks like it calls a PHP script that dumps something into $output. $retval is the return value from the system call. Read the manual on system(). Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771239 Share on other sites More sharing options...
Xu Wei Jie Posted February 25, 2009 Author Share Posted February 25, 2009 I would not understand what does php $var1 $var2 do.....??????? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771262 Share on other sites More sharing options...
Maq Posted February 25, 2009 Share Posted February 25, 2009 I would not understand what does php $var1 $var2 do.....??????? What are you talking about, $var1 $var2? Read the manual link I provided it will explain it a lot better than I can, it also provides many examples. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771271 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 It uses the php cli (command line interface) PHP CLI. What it is doing depends on what is housed in the two variables, as they hold the comments. Hence why Maq asked that. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771276 Share on other sites More sharing options...
Xu Wei Jie Posted February 25, 2009 Author Share Posted February 25, 2009 The first variables is the php file to be interpreted. I have no idea what is the second variable for.Thus, I am asking what could it be for? I normally use CLI like how I always used to i.e. php example.php Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771303 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 What does the second variable contain? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771306 Share on other sites More sharing options...
Xu Wei Jie Posted February 25, 2009 Author Share Posted February 25, 2009 $new_id = store_data(......); The second variable basically gets its value from the statement above which I am not sure what it does. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771311 Share on other sites More sharing options...
Maq Posted February 25, 2009 Share Posted February 25, 2009 $new_id = store_data(......); The second variable basically gets its value from the statement above which I am not sure what it does. That really doesn't help at all cause then we would need to know what store_data returns... Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771318 Share on other sites More sharing options...
Xu Wei Jie Posted February 26, 2009 Author Share Posted February 26, 2009 I have found out more. store_data() actually returns into $new_id another file name where objects are stored and serialized into. $frame is the name of another php file. Thus system("php $frame $new_id > src/$output_dir/$output", $retval); will run 2 CLI processes to direct the content of $frame into an output path and the other to deserialize the objects stored in $new_id. However there is something that I still don't quite understand. Does running php cli on 2 filenames interpret both of them and direct them into the output path? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771631 Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 $new_id is simply the argument passed to $frame. You need to look in $frame file to see what it does with its arguments. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-771634 Share on other sites More sharing options...
Xu Wei Jie Posted February 27, 2009 Author Share Posted February 27, 2009 Do you think this UNIX specific command can be implemented using PHP in built libraries? system("php $frame $new_id > src/$output_dir/$output", $retval); Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-772510 Share on other sites More sharing options...
trq Posted March 1, 2009 Share Posted March 1, 2009 Theres nothing UNIX specific about it. $frame obviously is a php script, why don't you look at it and see what it does? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-773516 Share on other sites More sharing options...
Xu Wei Jie Posted March 1, 2009 Author Share Posted March 1, 2009 What I heard was system function is very OS restrictive means it is not portable across platforms. Obviously I do know $frame is a php script. But i am exploring into php file i/o libraries to do the exact same thing as the command I typed does. The command does take in objects from $newid into $frame which is ran by system and direct its output to a specified file Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-773709 Share on other sites More sharing options...
trq Posted March 1, 2009 Share Posted March 1, 2009 So, use fopen and fwrite to write to these files from within the $frame php script instead. We really can't help much without seeing code. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-773711 Share on other sites More sharing options...
Xu Wei Jie Posted March 1, 2009 Author Share Posted March 1, 2009 Let's take away the $new_id which is supposed to be a file containing objects Let src/$output_dir/$output be a directory, we will name it src/out.php I will run system("php $frame > src/$output_dir/$output", $retval); Let's create a dummy php file and its filename to be assigned to $frame $frame = dummy.php dummy.php <?php echo 'This is a dummy'' ?> If I ran a system command like this, it will run dummy.php and output 'This is a dummy' to src/out.php If I use file i/o libraries, i can never run or achieve something like php $frame $new_id which is a command but I do not wish to use system command, thus I was thinking how should I work around it. Placing file functions inside the script may help but it will also means a lot more lines of codes. If i can do something like what system() can do and using php in built functions only, it would be great. Any ideas or alternatives? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-773731 Share on other sites More sharing options...
trq Posted March 1, 2009 Share Posted March 1, 2009 I really don't see the issue here. Put simply, you have a php file... <?php $new_id = 10; $output_file = 'src/foo/out.log'; include 'dummy.php'; ?> Then, in dummy.php... <?php ob_start(); echo "The id is $new_id"; // more script & output goes here. $out = ob_get_contents(); file_put_contents($output_file, $out); ob_end_clean(); ?> You could even wrap most of that into the calling script so dummy.php would be cleaner. This would make your calling script look more like.... <?php ob_start(); $new_id = 10; $output_file = 'src/foo/out.log'; include 'dummy.php'; $out = ob_get_contents(); file_put_contents($output_file, $out); ob_end_clean(); ?> While dummy.php would simply contain.... <?php echo "The id is $new_id"; // more stuff to output ?> I think your making this a hell of alot more difficult than it need be, either that or I am completely missing your point. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-774060 Share on other sites More sharing options...
Xu Wei Jie Posted March 2, 2009 Author Share Posted March 2, 2009 ob_start(); and ob_get_contents(); are new to me The solution you gave seems viable if $new_id is just a variable. Are there any file functions that given a php filename, I can run it and get the contents? I am just using pseudo code here i.e. $contents = runphp('filename', second parameter....,third parameter...) fwrite($contents to another file) Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-774336 Share on other sites More sharing options...
trq Posted March 2, 2009 Share Posted March 2, 2009 Are there any file functions that given a php filename, I can run it and get the contents? I am just using pseudo code here No, but you could easily make one. <?php function execphp($file, $args=array()) { ob_start(); extract($args); include $file; $out = ob_get_contents(); ob_end_clean(); return $out; } $contents = execphp('foo.php',array('bar' => 1, 'bob' => 50)); ?> This would make the variables $bar and $bob exist (and contain the values 1 & 50) within foo.php, execute the code within foo.php and return any output into $contents. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-774354 Share on other sites More sharing options...
Xu Wei Jie Posted March 3, 2009 Author Share Posted March 3, 2009 Thanks . It is quite a neat solution. However I have a problem here. I am not interacting with integer parameters but a file name($new_id) of a file that contain objects Pseudocode to simulate the command " php 'filename' $new_id " $contents = runphp('filename', $new_id); How do I code that to your execphp function? Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-775240 Share on other sites More sharing options...
Xu Wei Jie Posted March 3, 2009 Author Share Posted March 3, 2009 I did this. Not sure whether if I did it correctly function execphp($file, $args) { fetch_data($args); // this is a function to fetch the data from a file to initialize the objects ob_start(); include $file; $out = ob_get_contents(); ob_end_clean(); return $out; } I am still having some problem with it and debugging in the process Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-775257 Share on other sites More sharing options...
Xu Wei Jie Posted March 3, 2009 Author Share Posted March 3, 2009 I have found a problem. The include statement does process the file but the contents are not written back to the file. system command seems to run in a special way. i.e. if I put these lines individually in a script. they give you the same results <?php include("SecurityCheck.php"); ?> or <?php system("php SecurityCheck.php",$retval); ?> but in the background, they don't get processed the same way. Thus, I was looking for an alternative to the system command. thorpe, thanks for your script but it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-775285 Share on other sites More sharing options...
Xu Wei Jie Posted March 3, 2009 Author Share Posted March 3, 2009 Ignore my previous updates. I think I have found the problem I am working with a file that has a special extension Thus system("php example.xxx.php",$retval) can work fine as long there are php tags to be interpreted in there. However the include("example.xxx.php"); is not able to work. I think it has to do with the function itself. Thus, I am still working on an alternative. If you have ideas, let me know ^.^ Quote Link to comment https://forums.phpfreaks.com/topic/146895-system-function/#findComment-775295 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.