[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to run a process so that it won't timeout

Posted on 2009-04-04
5
Medium Priority
?
150 Views
Last Modified: 2012-05-06
I have a scheduling program in a web application written in PHP and MySQL, that times out every time it is run without fail. It does it's job, it just doesn't get to the end before the server times out, so my users need to keep launching it until all of the schedule slots are filled. I do not believe that I can make my process much more efficient than it currently is, so I need to figure out a way for the server to keep running it, even though it may take a long time (ie. 5 - 10 minutes)

My thought is that it must be possible to give the process over to the server so that it is not associated with the user's session. I suspect that if I were to run the process via Cron, it would run to completion without timing out.

What are my options here? My app is hosted on a regular, everyday LAMP provider where I only have as much control as offered by the cPanel.
0
Comment
Question by:dirknibleck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:cyberstalker
ID: 24069383
Just add

set_time_limit(1200);

In the beginning of the script.
0
 
LVL 15

Author Comment

by:dirknibleck
ID: 24074061
I haven't had success with set_time_limit in this script. It still times out after about 5 minutes. Is there no way to make a process run like a batch job? What if I want the process to keep running even if a user were to exit their browser?
0
 
LVL 10

Accepted Solution

by:
cyberstalker earned 2000 total points
ID: 24074954
If it aborts, it is probably because the browser cancels the request. There's two ways around this. You can either send something to the browser every now and then just to keep it happy (don't forget to flush() too), or you can use ignore_user_abort(), which will keep the process running even if the browser disconnects.

Of course you can also run the script from cron.
0
 
LVL 15

Author Comment

by:dirknibleck
ID: 24082966
What does the flush() do?

For sending data to the browser could I send back % complete and have an AJAX listener, or will that only run once http stops returning?
0
 
LVL 10

Expert Comment

by:cyberstalker
ID: 24084589
By default, PHP buffers output. This means that your output will only actually get send when the script finishes, when the output buffer is full or when you implicitly flush() the buffers.

So if you don't do the flush(), nothing will get send to the browser at all and the browser will still stop listening.

Sending a completion percentage to an AJAX listener will not do you much good, unless you apply a http push technique. I prefer to use multipart/x-mixed-replace documents, which are supported by most browsers, except Internet Explorer. You can also use a framework for it, like Comet.
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question