Welcome Guest, Not a member yet? Register   Sign In
Code crashes with error maximum execution time 300 secs
#1

[eluser]Praveen Subramaniyam[/eluser]
I'm using Code Ignitor as a PHP framework in my php project . I'm running the code in my system using Apache server . I have a setting for maximum execution time as 300 secs . My code has some 1000 rows in a mysql database , reads them and prints them in the terminal in a loop sleeping every 3 secs . But often the code crashes every 30 mins (approximately) saying maximum execution time 300 secs exceed in either DB_Driver.php or DB_active_rec.php . So I wrote a simple code which only prints some data in terminal 1000 times in a loop sleeping for 3 secs . Now this code also crashes every 6 hours (approximately ) . But when i run the same without Code Ignitor (i.e) without using classes just normal php file .. it runs indefinitely .. If i increase the maximum time out , the code crash after some times .. the maximum execution time and crash time seems to be proportional .. Can anyone please help me out in this
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You've not really explained why you need to loop through each of these entries. If you could explain in more detail what your app is supposed to be doing and why, I'm quite sure we could suggest a better working alternative for you.

The maximum execution time limit is there for a reason. If your code even comes close to exceding it, then there's a pretty good chance that there's a much better way to do what you're trying to do.
#3

[eluser]Praveen Subramaniyam[/eluser]
I have an UI page which allows users to enter some message . Those messages are stored in DB with some indicator to say whether its read or not (a field with values 0 or 1) . Ill poll that table every 3 secs to read the unread messages (while loop which runs indefinitely). If there are some unread messages ill read them and print them in terminal and will mark as read .like this the loop continues ...
#4

[eluser]TheFuzzy0ne[/eluser]
Any PHP script that runs indefinitely on a Web server is a bad idea. You'd be much better off setting up a cron job, although I doubt that would work in this situation, or using AJAX to periodically request more data from the server. At least that way, you can handle things in much smaller, bite-sized pieces.

If you require a constant connection to the server, then PHP is not the way to go. You'd be better off using a different protocol like IRC, which has has the ability to push data to connected clients when necessary.

HTTP will eventually support persistent connections to the server, which will give you the ability to push data to connected clients, but for now, to the best of my knowledge, you can't.
#5

[eluser]Praveen Subramaniyam[/eluser]
Thanks for the reply .. Smile I think this I can solve with cron .

But in another code im listening indefinitely in a socket (a server code) . I think i cant solve this with cron jobs .. i can restart the code but every client needs to connect again which is a little burden on client side . Can u pls suggest me an idea for this ??
#6

[eluser]TheFuzzy0ne[/eluser]
I'm starting to reconsider my original position. It seems that with PHP sockets, you can do what you want, but the script has to run indefinitely.

Personally, I'm not keen on the idea of keeping loops running indefinitely, because you could end up with considerable overhead without even realising it. Also, if you're on a shared Web host, they most likely prohibit running daemons and any other kind of service that runs indefinitely, so you might want to look into that.

However, this article might help you: http://devzone.zend.com/209/writing-sock...rs-in-php/

Please let me know how you get on.
#7

[eluser]Praveen Subramaniyam[/eluser]
I have already setup my server with php sockets and with CodeIgniter as a php framework . The code uses the model class from CodeIgniter for database connections . But my code crashes frequently with the problme maximum execution time 300 secs exceeded . But before using this CodeIgniter for DB connections and others , i didn't have this problem of maximum execution time .. So my concern is whether i must be using the CodeIgniter api's wrongly and so i need a solution for this .. How a normal php file with while loop runs indefinitely but when run through CodeIgniter crashes often as said before .. does CodeIgniter do caching or something which makes the file system to slow down ??
#8

[eluser]TheFuzzy0ne[/eluser]
I've not used sockets before, so I don't have much to say on the subject.

However, at the beginning of the code of the tutorial I linked to, you'll see:
Code:
set_time_limit (0);

That may be your solution. As far as I am aware, you need to execute your code once to set up the listener, and then from that point on it's up to you where your app flow goes. Since I can't see how you're setting up your listener, I can't really comment.




Theme © iAndrew 2016 - Forum software by © MyBB