Jump to content

code execution


user4fun

Recommended Posts

I heard that there are li9mits on how long a php code will run for?? is that truealso, the sleep() mode sucks, is there anyway arround that to actually have this formatexecute some codestop for a few secondsexecute more code..I personally think the sleep() is stupid. what else are there, tricks maybe.

Link to comment
Share on other sites

I heard that there are li9mits on how long a php code will run for?? is that truealso, the sleep() mode sucks, is there anyway arround that to actually have this formatexecute some codestop for a few secondsexecute more code..I personally think the sleep() is stupid. what else are there, tricks maybe.
Maybe you should look into while/for & if else statements. This can be done easily.
Link to comment
Share on other sites

If you want to pause execution, sleep is the only way. Let me mention that there are very, very few situations where you would use sleep in a web page context. You would only use sleep if you want a script to keep running while it is waiting for an event to occur, such as an asynchronous response from a server or waiting for a file lock to be released. But you need to understand that the user only sees the result of the PHP script after execution stops. That is why people don't use sleep in a web situation, you want the script to finish as soon as possible so that the user sees their web page. If you use sleep, you are only delaying the time that it takes the script to finish executing.So, the question is not what are the alternatives to sleep, the question is what are you trying to do. Chances are there is a better way then using PHP.Also, the max_execution_time configuration option controls how long a script is allowed to run before being stopped. The default value for max_execution_time is 30 seconds.

Link to comment
Share on other sites

The user choses to start file review.They are randomly selectedone file shows upthat is when i want the execution a stop for maybe 5 secondsthat file is closedAnother fie shows upand 5 more send wait then again athat is it, well so far. lol

Link to comment
Share on other sites

You need to use Javascript to do that. You will use PHP to give Javascript the filenames or whatever you want to change every 5 seconds, but Javascript would be responsible for getting the next name from a PHP script and updating the page with the new name. That's what people use AJAX for, so do a search for AJAX tutorials to see that. It looks a little complicated, but the hardest part is just finding out which AJAX object the browser supports in the first place. Javascript also has a setTimeout function that you can use to run another Javascript function (or the same one) in another 5 seconds.

Link to comment
Share on other sites

sounds exciting, okay let me see if i got this right before i go read a bunch of tutorialsi will have two files1) get_info.php2) display_file.htmwhen the user decides to view the files they will go to display_file.htmdisplay_file.htm will ask get_info.php for the first file to viewdisplay_file.htm will dispaly that file wait 5 seconds Close the fileThen ask get_info.php for another name.Do i understand the concept right?if i do then my php file needs to randomly pick one file only.so display_file.htm would process it. then asks get_info.php to randomly select another one.the display_file.htm would have a loop in it to decides how many times we will ask get_info.php file to randomly select one.Is that right?

Link to comment
Share on other sites

Yeah, that's right. You can actually do it one of two ways. You can either keep an array inside Javascript that will keep track of all the files that the PHP file has already sent, and keep asking for a new one whenever it gets one it already saw, or you can have Javascript send the list of files it's already seen to the PHP page and then PHP will make sure that it chooses a file that it hasn't already chosen. That would probably be the best way to do it, because that way you could have the PHP page send a special value if there are no more files, if they have seen them all. If Javascript kept a list then eventually it would just be in an infinite loop asking the PHP page for the next file. When you send the request to PHP for another file you can include a bunch of information for $_POST the same way as if you submit a form, and read it on the PHP page. So Javascript could take the array of files it's already seen, copy everything into something inside $_POST and send the request to the PHP page. Then the PHP pages reads the list of files that were already seen, and grabs another one. You can even include that list of files in the SQL query to make sure that the SQL query only returns one that hasn't been seen so you don't need to have a loop in PHP. If the database or PHP can't find a file that hasn't been seen (if they have seen them all), then it can send a value like -1 or something back to the Javascript, and Javascript will check for a value of -1 and if it sees it then it will indicate to the user that they've seen everything.

Link to comment
Share on other sites

Actually, i need to make it to where they will keep seeing files untill they choses to stop it manually, and the files can be repetitive. I think i will just make a form with start and stop buttonstart will ask the php file for infromation ajax will display it and then ask a gain. if a file has already been chosses that is okay to view ti again.Eventually the user will see something they like and say stop, if they change their mind they can hit start again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...