Doqrs Posted January 23, 2007 Share Posted January 23, 2007 HelloHere is the scenario:I have a PHP page that a visitor visits after uploading a file.we'll call it "uploaded.php"within uploaded.php is some code which gets the $_FILES data, displays all the appropriate stuff, etc.In uploaded.php i would like to call another php file, example: updateID3.php?id=123, where id is a col in a mysql database. I want the updateID3.php file with params to be executed independent of the Client viewing the uploaded.php page.So the browser continues to parse and display the uploaded.php page while updateID3.php with parameters is running on the server (almost like a cron job but running instantly and only once)I hope i was descriptive enough.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/ Share on other sites More sharing options...
bibby Posted January 23, 2007 Share Posted January 23, 2007 I don't see the question here.Your plan sounds like it would work, so what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-166941 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 so the question is: how do i do it? Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-166944 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 any help is greatly appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167480 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 Easiest way is to write a function, save it in your 'other' file and then 'include' that file into your uploaded.php script and call the function. That way when the uploaded.php script executes it will also execute the function you wrote in the included file. Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167502 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 The only problem with that is it will be executing the function while the page is rendering. I want something similar to a cron job, which is independent of client actions. In the example i used above, when the user goes to uploaded.php, i want the server to run updateID3.php?id=123 regardless of whether the user closes out of uploaded.php or not, IE it is happening server-side.The functions on updateID3.php?id=123 are not quick, and would take a long time to render the page before uploaded.php is displayed if the file is simply included. Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167540 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 Ok, so you don't want it to run each time someone accesses the uploaded.php script. Even if you're going to use 'cron' then you'll need to have something that executes each time someone accesses the uploaded.php file that writes the data you need into a text file or database, for example, that would contain the necessary details you need for your update parameters like user_id, etc. Then, set up a cron to run something like update_cron.php that runs the queries you need by accessing that text file (or database tables). Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167550 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 I do want it to run every time someone is on uploaded.php (it only occurs after file uploads) because i want the server to transcode the file format but this takes a lot of time.During heavy traffic times, i think it would be a lot better to have multiple instances of updateID3.php running rather than have a cron job run every minute and pick up and transcode all of the uploads in the last minute (at 3am this could be none, where as it could be a dozen around 9pm). Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167556 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 Hmmm...ok, here's the problem. A script can't execute unless it's told to execute. That's exactly what cron does...tells things to execute at specific times. Otherwise i'm not aware of any magical solution that allows scripts to operate on their own. As far as I can see you have the two choices. Run a cron as often as you wish or have a sub-script run simultaneously with your main script that updates the data you're seeking. Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167566 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 alright, so could you set up a basic layout of how the update_cron.php script would work?thanks a lot for your help Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167571 Share on other sites More sharing options...
Deltran Posted January 23, 2007 Share Posted January 23, 2007 What you can do is use the register_shutdown_function function: http://us3.php.net/register_shutdown_function[code] //stuff you do at the begining of page function stuff_uploadID3PHP_does(){ global $id_this_function_needs; //code here } register_shutdown_function('stuff_uploadID3PHP_does'); //Rest of Page[/code]This will run that block of code when the page is done.You may also need to use ignore_user_abort (http://us3.php.net/ignore_user_abort), but I doubt it... Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167573 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 Option #3! Thanks Deltran. :)How it would work would be dependent upon how you handle the data. For example, if your uploaded.php script writes info to a MySQL database then this secondary function would need to access it if you want to transfer some of that data to another location. Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167577 Share on other sites More sharing options...
Doqrs Posted January 23, 2007 Author Share Posted January 23, 2007 I've realized that the function i am attempting to do is similar to that of youtube converting your video to .flv format after you upload it. You can continue to browse the site with no functional adherents, but the server is still processing an assigned request on your behalf. .. maybe this helps? Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167585 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 Ok, then the function setup that Deltran specified would work perfectly as it does what you've outlined. It continues to execute code after the original script has finished. Check out the link he provided for full details on it. Quote Link to comment https://forums.phpfreaks.com/topic/35308-php-server-side-execution/#findComment-167598 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.