0

I have a windows pc with apache running, and I needed a php script to continuously run to listen to inputs coming from a UDP port, and take the required action and send it back.

The only way I know how to do this, is to install curl for cmd, and run the php script with a WHILE loop. What I am afraid is that this is the wrong way to do it.and may be unreliable and take up large amount of system resources.

Can people comment on the above method? I have heard of cron..but thats for unix only? What can I do?

1
  • I have heard this can be done with windows task scheduler? But that does not allow you to say run the script every minute. the worse case scenario is that I have to write my own scheduling app in C# :( Commented Feb 17, 2013 at 18:15

2 Answers 2

2

Hey try this below solution. Use a bat file and schedule to execute that bat file.

For example in the bat file executephp.bat, write this

c:\xampp\php\php.exe -f c:\xampp\htdocs\do_something.php

save that bat file that contains that line.

Go to windows scheduler and create a new task and in action tab, browse to point that executephp.bat and for start in -> direct to the directory u have that executephp.bat.

For example if u save the file under C:\xampp\htdocs put that C:\xampp\htdocs in the start in.

Remember to invoke the script even when the user is not logged on.

Everything is set and it will execute without problem.

Sign up to request clarification or add additional context in comments.

1 Comment

I have a question. Is there a way I could invoke the file to open? Say with a url link from another system. Once a user calls it, it will somehow execute the batch file..?
0

A PHP script behind Apache will always have a maximum execution time, so the while-loop should always be stopped after the specific timeout.

You should better use cron or a batch script like Venkat recommended. There are some great services for cron out there, that will do a GET request to your server and run the script. Have a look at this related thread: Scheduled Request to my website from an external source

Doesn't that fit your needs?

2 Comments

any idea how long does it last? I could always time it out and re-open it but I want to know how long it lasts anyway
Have a look here at the max-execution-time in PHP, that is default 30 seconds. For Apache it says: "Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.