cgm225 Posted October 24, 2007 Share Posted October 24, 2007 If I am running a PHP script that is executing many system commands that each take a while to run, is there a way to "queue" those system commands on the server somehow and allow the script to move on (i.e. finish executing everything else)? Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/ Share on other sites More sharing options...
effigy Posted October 24, 2007 Share Posted October 24, 2007 On what OS? Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377037 Share on other sites More sharing options...
cgm225 Posted October 24, 2007 Author Share Posted October 24, 2007 Debian 4.0 Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377040 Share on other sites More sharing options...
effigy Posted October 24, 2007 Share Posted October 24, 2007 You can fork the processes. Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377050 Share on other sites More sharing options...
cgm225 Posted October 24, 2007 Author Share Posted October 24, 2007 Thank you for your help. I read the php manual, but wanted to know if you could you help me with an example? Let's say I want to run the followin command five times.. system("convert $photos_server_path/photos/$album/$buffer$number.jpg -resize 250x -gravity center -quality 100 -crop 250x141+0+0 $photos_server_path/photos/$album/thumbnails/small_thumbnail-$number.jpg"); ..how would I do that by forking the process? Also, if someone is running the script, what happens if they refresh the page, will the same command get sent again? Thank you so much. cgm225 Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377063 Share on other sites More sharing options...
effigy Posted October 24, 2007 Share Posted October 24, 2007 Thank you for your help. I read the php manual, but wanted to know if you could you help me with an example? Not at the moment; however, there's an in-depth introduction here that will probably do a better job. Also, if someone is running the script, what happens if they refresh the page, will the same command get sent again? I would assume this to be the same thing as an abort, but I'm not sure of all the logistics. Take a look at Connection Handling. Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377079 Share on other sites More sharing options...
Daniel0 Posted October 24, 2007 Share Posted October 24, 2007 Also, if someone is running the script, what happens if they refresh the page, will the same command get sent again? The process control functions shouldn't be used within a web server environment. See: http://php.net/pcntl Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377104 Share on other sites More sharing options...
effigy Posted October 24, 2007 Share Posted October 24, 2007 The process control functions shouldn't be used within a web server environment. Good catch. is there a way to "queue" those system commands on the server somehow and allow the script to move on What kind of processing are you doing that you need to move on before/while these other commands are processed? Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-377110 Share on other sites More sharing options...
roopurt18 Posted October 28, 2007 Share Posted October 28, 2007 It looks like he's running a command that resizes images, probably to thumbnails. On *nix you can direct the output of the command to /dev/null and it will execute without holding up your PHP script. Although I sort of have to wonder why you'd want to do that with an image resizing command; granted there are a lot of variables but the one my application runs is very fast. Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-379968 Share on other sites More sharing options...
zq29 Posted October 29, 2007 Share Posted October 29, 2007 It looks like he's running a command that resizes images, probably to thumbnails. On *nix you can direct the output of the command to /dev/null and it will execute without holding up your PHP script. Although I sort of have to wonder why you'd want to do that with an image resizing command; granted there are a lot of variables but the one my application runs is very fast. If so, the images could be large... I have been using ImageMagick recently to process images that are 24,000px by 18,000px - It took my machine about 30 minutes to resize the thing! Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-380179 Share on other sites More sharing options...
cgm225 Posted October 31, 2007 Author Share Posted October 31, 2007 @SemiApocalyptic - That is exactly the problem I am having, and I do not want my script to wait for the server to complete the thumbnail generation with ImageMagick. Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-382176 Share on other sites More sharing options...
effigy Posted October 31, 2007 Share Posted October 31, 2007 From system: Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends. Quote Link to comment https://forums.phpfreaks.com/topic/74601-is-there-a-way-to-queue-system-commands/#findComment-382186 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.