Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    62
    Thanks
    19
    Thanked 1 Time in 1 Post

    Running a PHP script from a PHP script.

    Alright..

    So I tried something simple to overcome the problem that
    I cannot run easly conrjob's in second on LAMP/WAMP. I created
    a tiny script that would be developed futher but I came up
    with a problem at the beginning.

    PHP Code:

        $secondrunner
    =0;
        while(
    $secondrunner 3) {
            
            include(
    "runthis.php");
            
            
    $secondrunner+=1;
                    
    //sleepy here
        

    I would call this script once a minute, but this script would call another
    script more frequently than once a minute. This way I could get a cron job
    to happen faster than 1 minute intervals.

    problem: First run goes fine of course, but when this script would repeat itself
    It cannot of course redeclare the same functions which are in the
    "runthis.php" script. Fatal error: Cannot redeclare function().

    How can I make the script to forget that the functions are already declared
    and so to say start from an empty table? Id like to know the aswer, thanks =)

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    You would need to declare functions in a separate script and inlcude it at the top.

    runthis.php would only call these functions.

    Of course you could check if a function exists with function_exists() and declare it only if it does not, but I would really strongly recommend against it.

    Simply divide runthis.php into 2 scripts: with function declarations and with calls to the functions. Then include function declarations at the top and include function calls in the loop.

  • Users who have thanked SKDevelopment for this post:

    SystemJay (10-12-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    62
    Thanks
    19
    Thanked 1 Time in 1 Post
    Ah yes, quite logical =)
    I was thinking that PHP would have some sort of syntax way for this,
    but yes, that works quite well. Thank you for puttin my gray matter in line.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •