spectator Posted February 28, 2010 Share Posted February 28, 2010 hey guys, i'm a php newbie, but i've worked with c++ and java most of my life. i am working on a web project now and ran into this problem: i am using a cron job to update a db every night. the php file that is used, has several (4) other php files that are executed sequentially in this form: exec("<filename>", $output); print_r($output); here is the problem; if i run the 4 scripts from command line (on the server), they execute perfectly; DB is updated correctly and all is well in the world. before i get any further, here's what the 4 scripts do: 1. download some text files 2. update db with that info 3. remove expired info from db 4. delete text files from server when i run the one file (let's call it "run_all") both from the command line and cron job (i'm saying this b/c i tested the cron jobs, and it's not the issue), i get the following output: Array ( [0] => X-Powered-By: PHP/5.2.12 [1] => Content-type: text/html [2] => ) Finished executing download script 2. Started updating the DB Array ( [0] => X-Powered-By: PHP/5.2.12 [1] => Content-type: text/html [2] => [3] => Opened file [4] => Opened database [5] => An error has occurred. No item(s) added. [6] => File closed successfully! ) Finished updating the DB 3. Started removing expired info from DB Array ( [0] => X-Powered-By: PHP/5.2.12 [1] => Content-type: text/html [2] => [3] => Error: Could not connect to database. Please try again later. ) Finished removing expired info from DB 4. Started deleting text files from local directory Array ( [0] => X-Powered-By: PHP/5.2.12 [1] => Content-type: text/html [2] => ) Finished deleting text files from local directory i guess that one way to solve this(maybe) is to make the 4 files run at 5 minute intervals in 4 different cron jobs however, i would still like to do just one file; i would appreciate any suggestions; i could be doing something that is taboo and i just have not learned it yet. cheers Link to comment https://forums.phpfreaks.com/topic/193693-using-exec-to-run-scripts-that-update-a-db/ Share on other sites More sharing options...
Spikerok Posted February 28, 2010 Share Posted February 28, 2010 If timing is important: we can try storing task number and time. So, we done task 1, set task = 2 and time when task 1 was done, so set time = 13:10. Then when time is 13:15, check if 13:15 - 13:15 = 00:05, then if difference between them is 00:05 or more do next task which is 2, and increase task by 1, and set new time once it gets to task 4, change task to 1. If time not important: if you have cron job every five minutes we just store task number. here is example of procedure: task = 1.. do task 1 task = task + 1 then next time cron runs file, task = 2.. do task 2 task = task + 1 for storage we can use database or file. Link to comment https://forums.phpfreaks.com/topic/193693-using-exec-to-run-scripts-that-update-a-db/#findComment-1019531 Share on other sites More sharing options...
spectator Posted February 28, 2010 Author Share Posted February 28, 2010 i think that is one item in question - is this operation time-dependent? still, i would rather see a solution that goes through the scripts one item at a time and finish as soon as possible. Link to comment https://forums.phpfreaks.com/topic/193693-using-exec-to-run-scripts-that-update-a-db/#findComment-1019546 Share on other sites More sharing options...
Spikerok Posted February 28, 2010 Share Posted February 28, 2010 if you want to just go through all scripts, you can include all files in order you want and run cron job on that script Link to comment https://forums.phpfreaks.com/topic/193693-using-exec-to-run-scripts-that-update-a-db/#findComment-1019553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.