I'm trying to run a command that outputs when the results whenever something changes. However, I keep getting an in_array() expects parameter 2 to be array, resource given in
error.
Here is my code:
$call = "~/www/reteps.tk/go/kahoot-auto " . '262671' . " " . 'bob' . " ";
$result = array();
$old_result = array(0 => "something");
$handle = popen($call, "r");
$result = file($handle); #is this how I read the results?
while (in_array("end",$result) != true) {
sleep(1);
if ($result != $old_result) {
echo($result);
$old_result = $result;
}
}
Full Error log:
PHP Warning: file() expects parameter 1 to be a valid path, resource given in /home/retep/www/reteps.tk/school/kahoot2.php on line 70
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
PHP Warning: in_array() expects parameter 2 to be array, null given in /home/retep/www/reteps.tk/school/kahoot2.php on line 71
Can you provide the value of $call? The error seems to indicate that it's a resource instead of a path. popen() requires a $command:
http://php.net/manual/en/function.popen.php
So $call should be a string of some kind, either a Linux command or executable file path or something. Right now $call appears to be a resource, so the path or command may be INSIDE of the resource and you just need to point to that value instead of the resource itself.