How to run a code without open page in PHP [duplicate]

4

I have PHP code that uses FSOCKOPEN to check the port of a server, and depending on the response it logs ... But for that the page has to always remain open, I would like to know if it exists some way I'd leave this running automatically on the server without user interface ...

Today for it to work I leave an HTML tag updating the page every 10 seconds ... But as I said, to run the page you always have to stay open!

    
asked by anonymous 12.09.2016 / 22:31

2 answers

0

Dear friends, I was able to solve the problem by following the step-by-step instructions in the following article: Source: Run PHP script in Windows Task Scheduler

  • Type cmd taskschd.msc and click basic task:

  • Typeandtitleandnext:

  • Selectdaily:

  • Schedulewhenyouwanttostartandthenumberofintervaldays(ifwanttodailyleave1):

  • SelectStartProgram:

  • Addthephpprogramandintheargumentsaddthepathofthescriptphp:

  • Click Finish.
04.10.2016 / 00:07
3

If you are using Linux , you can use the crontab >:

*/12 * * * *  /usr/bin/php -c /etc/php5/apache2/php.ini /var/www/html/seu_php.php

Where:

  • 12 = 60 seconds / 5 seconds (every 5 seconds)
  • / usr / bin / php = path of your PHP executable
  • /etc/php5/apache2/php.ini = path of your php.ini file (PHP configuration)
  • /var/www/html/seu_php.php = The full path of the PHP script you want to run

If you are using Windows , put it in the task scheduler:

c:\WAMP\php\bin\php.exe -c c:\WAMP\php\php.ini c:\WAMP\www\seu_php.php

Where:

  • c: \ WAMP \ php \ bin \ php.exe = path of your PHP executable
  • c: \ WAMP \ php \ php.ini = path of your php.ini file (PHP configuration)
  • c: \ WAMP \ www \ your_php.php = The full path of the PHP script you want to run
12.09.2016 / 22:42