ignace Posted May 17, 2012 Share Posted May 17, 2012 This code works outside of the while, but not inside while ($row = mysql_fetch_assoc($res)) { $host = $row['host']; $cmd = exec("mysql -h$host -e \"show status like 'wsrep_cluster_size'\""); echo $cmd; } I have found nothing on google, stackoverflow or the php manual that explains why this does not appear to work inside a loop? Quote Link to comment https://forums.phpfreaks.com/topic/262665-exec-inside-loop-does-not-work/ Share on other sites More sharing options...
ignace Posted May 17, 2012 Author Share Posted May 17, 2012 Phew. Found it I just needed to add escapeshellarg Can't believe I didn't try it in the first place, since it's on the PHP exec() function manual.. Quote Link to comment https://forums.phpfreaks.com/topic/262665-exec-inside-loop-does-not-work/#findComment-1346273 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 What does it do inside the loop? Does it throw an exception or just return nothing? Likely that status variable isn't changing in the context of your loop. Quote Link to comment https://forums.phpfreaks.com/topic/262665-exec-inside-loop-does-not-work/#findComment-1346274 Share on other sites More sharing options...
ignace Posted May 17, 2012 Author Share Posted May 17, 2012 The script appeared to hang and returned nothing. Still don't quite understand though why it works outside of the loop without the escapeshellarg() and not inside the loop. Other people have reported the same problem but they didn't have the same case as me (passed the var as second parameter) hopefully this post will help someone in the future who made the same silly mistake Quote Link to comment https://forums.phpfreaks.com/topic/262665-exec-inside-loop-does-not-work/#findComment-1346277 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.