-1

when tring to run powershell script using $out = shell_exec('powershell.exe -command C:\xampp\htdocs\web\ping.ps1 < NUL'); echo $out;

it hangs and noting is done , the page just keep loading , that's my simple script

ping 8.8.8.8 -t

i used this command in powershell in order to allow executing scripts at first ,

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

but nothing changes . I need help , how to execute powershell scripts using php ?

1 Answers1

0

This is happening because the tag -t gives the command prompt the command to continue pinging until it's interrupted.

The constant loading is php executing the power shell script and waiting for said script to stop executing before continuing. Because your power shell script never stops until you navigate away from the page. It'll constantly load

So the interruptions would be php memory being maxed out and failing. Or the user navigates away from the page which halts execution. Please review

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sag_tcpip_pro_pingconnect.mspx?mfr=true

I would recommend using a count then capturing the input after execution

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
  • Note to all users with editing permission. I am currently mobile so if one could spend a moment tying this up and using appropriate url tags on the Microsoft link. Then it'll be much appreciated. – Daryl Gill Aug 07 '15 at 19:50
  • Oh thanks , it works :D , the problem was the ` -t ` in the ping order which make the webpage hangs forever ,Thank u – Moataz Farid Aug 07 '15 at 22:38
  • Indeed. If you check the Microsoft link I provided it'll give you information on all the arguments you can add instead. My best opinion is to use the count (can still cause the page to hang) for 1 or possibly 2 no more than 4. Capture the input and use as you need it.. if you don't mind the follow up. Why do you need to perform this task? As I'm sure you could possibly move it to a scheduled task and work with the database based on the scheduled task? – Daryl Gill Aug 07 '15 at 22:42