1

Main problem is how to create a PHP file automatically and run it on server for some time? Like when I load abc.php file in my browser it will first create a xyz.php file on server and run it on server side for some specific time and when time completes it will reloads the abc.php file.

Any help please, I want this soon.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
arslaan ejaz
  • 1,001
  • 13
  • 31

1 Answers1

1

You can use the crontab

And in your contab you put something like :

*/5 * * * * /usr/bin/php /path/to/your/file.php

And your "file.php" script will be launched every 5 minutes.

Manage your schedules on a database, file.php may run any code you want when a time expires.

Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
  • You mean if i run a file abc.php in my browser, this file run the command like "*/5 * * * * /usr/bin/php /path/to/your/file.php" , then this file.php will run for some time and also it will close after some time or loads agian the abc.php file.? am i right? – arslaan ejaz Sep 14 '12 at 05:55
  • 1
    No, this file.php is executed on the system all the time every 5 minutes even if you didn't launched it on your web browser. But if your file.php reads in a database the actions it has to do, then it could do them. – Alain Tiemblo Sep 14 '12 at 06:24
  • Thanks ninso for all the help, but this is the main issue. Actually i have a chatroom which has random topics that runs for 10 -15 min, then page reloads and new topic will come. I want a file that runs when i open chatroom and automatically bring topic from db and show topics in chatroom to all users in the world.So i want file.php run when a new chatroom created to bring its topics and close that file.php when chatroom will be closed. I think i am annoying you, but plz help, this is my issue. – arslaan ejaz Sep 14 '12 at 06:27
  • In such a way, you can use `exec("php /path/to/file.php > /dev/null 2>&1 & echo -n \$!");` on your code, and in file.php you put `sleep(seconds);` and then execute your code. See [this answer](http://stackoverflow.com/questions/12341421/multi-threading-in-php/12341511#12341511) for details about this command. – Alain Tiemblo Sep 14 '12 at 06:40