Jeffro Posted August 15, 2011 Share Posted August 15, 2011 I have a page1.php which calls page1insert.php via require_once. page1insert.php has about 10 functions and then does a database insert. This works great. The problem... I have about 100 different page1's (page1.php, page2.php, etc..) that need to call 100 of these different insert.php pages (all doing different database inserts to the same database/table). Running these all individually works great but I'm wanting to figure out a way to run all 100 as a cron job. I thought I could just create a new cron.php page and put the following in: include 'page1.php'; include 'page2.php'; include 'page3.php'; include 'page4.php'; etc... Unfortunately, as soon as it hits page2insert.php this gives: Cannot redeclare clean_url() (previously declared in... /mypath/ of page1insert.php. Any idea what's causing this and how I might make it work? When I google this, it says that using a require_once will resolve the problem but that's not happening. Since all my insertpages have different names and are being called separately by each page1 (page2, page3, etc), I didn't think this would be an issue. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/244847-getting-cannot-redeclare-error-and-trying-to-find-a-workaround/ Share on other sites More sharing options...
Adam Posted August 15, 2011 Share Posted August 15, 2011 I'm guessing that in every insert file you're redefining the "clean_url()" function, and perhaps more after. Move all of these generic function(s) into a file of their own and require_once that separately within each insert file. You need to include it there and not within the cron file so that theycan still be used separately. Quote Link to comment https://forums.phpfreaks.com/topic/244847-getting-cannot-redeclare-error-and-trying-to-find-a-workaround/#findComment-1257759 Share on other sites More sharing options...
Jeffro Posted August 15, 2011 Author Share Posted August 15, 2011 I'm guessing that in every insert file you're redefining the "clean_url()" function, and perhaps more after. Move all of these generic function(s) into a file of their own and require_once that separately within each insert file. You need to include it there and not within the cron file so that theycan still be used separately. Thank you! You were exactly right and it worked. Whew! Quote Link to comment https://forums.phpfreaks.com/topic/244847-getting-cannot-redeclare-error-and-trying-to-find-a-workaround/#findComment-1257770 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.