0

I'm making a project on PHP and it pretty much doesn't involve any human intervention, in other words, I'm making a special script that should run for a long time (a user visits my website and the script keeps running until the user exits...). The one problem that is concerning me is:

Won't the sessions expire when the script runs like this for a while? If So how could I bypass that, so it could run for a very a long time?

Oh, And one more question: Could my PHP script start by its own without any user intervention? If so, How could I configure it to do so?

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
user1494517
  • 311
  • 1
  • 3
  • 11
  • 1
    This [SO answer](http://stackoverflow.com/a/1270960/678801) will probably be relevant to you. – Christofer Eliasson Aug 07 '12 at 18:21
  • Without knowing what you're trying to accomplish it's pretty much impossible to answer your question. I will say this though, PHP isn't really made for long-running scripts. It's made for short-lived request/response cycles. If you need something to keep running on the server you might be better off looking at java, node.js, or any of a number of other languages that are better suited to the task. – GordonM Aug 07 '12 at 18:22
  • Also, is timeouting a real word? – Mr Lister Aug 07 '12 at 20:15

2 Answers2

1

You can run PHP from the command line. Those scripts do not have a timeout like user-called scripts. Otherwise, you can set the timeout with set_time_limit like

 set_time_limit(0); // 0 means no limit

See http://php.net/manual/en/function.set-time-limit.php

Willem Mulder
  • 12,974
  • 3
  • 37
  • 62
1
  1. You can use set_time_limit(0) to avoid the timeout.
  2. For the PHP script to start on its own, you could use a cron
Josejulio
  • 1,286
  • 1
  • 16
  • 30