Jump to content

can the same script run twice??


sangoku

Recommended Posts

Hy i am making a script which should by first run execute ti self, and show me some data..(works so far) later when i pres submit the page should reload it self and do some file manipulation.... works to

 

BUT i wanted the file to show me the current status of the comparison.... so i made it so it shows the curent state.... but the thing is, as long the script runs i cant see the page... it puts me on the holding line QQ... how can i bypass this... except :confused: making the stat file outside the file .....

Link to comment
Share on other sites

I'm not really sure what you're trying to do here.

 

BUT i wanted the file to show me the current status of the comparison.... so i made it so it shows the curent state....

 

I'm not sure what you mean by show the status of the comparison.  Do you mean show you the information before you ran the script and the information after you ran the script?

Link to comment
Share on other sites

He wants to show a progress bar while his loop loops. Wouldn't it be easier if you looped in JS instead of PHP? And your PHP script would provide you with the correct data?

 

If you want to have a shot at this but your PHP script loads data from your DB use mysql_unbuffered_query this will send the query to your MySQL server but will not load and cache the results which means that when your PHP script ends, MySQL will still have your result which allows for retrieving the DB records through Ajax.

 

This comes at a cost: you can't perform another query until the entire result has been processed.

 

I also want to note that this is untested I just thought of it when I typed the reply.

Link to comment
Share on other sites

IT is NOT possible to make anything from client side!!!  I CAN ONLY execute the script on server side!!! and the damn  server just wont let me acess the session data because the script that is in execution uses it Q.Q  i will see if i can bypass it somehow.....

Link to comment
Share on other sites

ok here is the complete script if someone can figure how to make it work pls help me out here....  i am on end with my Latin....

 

here is cleanupScript.php

 

<?php
    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    $password = 'password1';

    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    //////////change this pasword to your personal one////
    /**
    * 
    */

    /**
    * @copyright  at ©sinisaculic@gmail.com, all rights reserverd 2009-2010
    * @author Siniša Čulić
    * @version 1.0
    * @created 31-mar-2010 13:51:17
    */


    session_name('cleanup');  //we set the session name
    session_start();         //we start the session cleanup
    //$remaining_time =  $_SESSION['remaining'] ;    //set the remaining time of the script to 0 for no note sake XD
    //unset($_SESSION['cleanup_in_progress']) ;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Parameter setings</title>
    <style type="text/css">
        body{
            color:#555555;
            font-size:13px;
            background: #eeeeee;
            font-family:Arial, Helvetica, sans-serif;
            width: 100%;
            margin-left: 5%;
            margin-bottom: 12 px;
        }
        .alert{
            color: #110259;
            font-size: 4em;
            font-family: cursive;
        }
        .note{
            font-size: 0.9 em;
            color: #006;
        }
        .database_data{
            background-color: #969696;
            width: 90%;     
            padding: 12px;
            border: #808080;
            border-width: thick;
            border-style: groove;
            margin: 5px;                
            -moz-border-radius: 10px;
            -webkit-border-radius: 10px;
            border-radius: 10px
        }

        .data{
            background-color: #969696;
            width: 40%;
            padding: 12px;
            border: #808080;
            border-width: thick;
            border-style: dashed;
            margin-left: 40px; 
            -moz-border-radius: 10px;
            -webkit-border-radius: 10px;
            border-radius: 10px;
        }
        .imposible{

            background-color: #FFFFFF;
            width: 42%;
            font-size: 2em;
            padding: 12px;
            border: #808080;
            border-width: thin;
            border-style: dashed;
            margin-left: 40px;
            margin:1em;
            -moz-border-radius: 5px;
            -webkit-border-radius: 5px;
            border-radius: 5px;
            text-align: center;
        }
        .header{

            background-color: #FFFFFF;
            width: 50%;
            font-size: 2em;
            padding: 12px;
            border: #808080;
            border-width: thin;
            border-style: outset;
            margin-left: 40px;
            margin:1em;
            -moz-border-radius: 15px;
            -webkit-border-radius: 15px;
            border-radius: 15px;
            text-align: center;
            font-family: cursive;
            font-size: 4em;

        }
        .button{
            font-family: Arial, Helvetica, sans-serif;
            font-size: 3em;
        }
    </style>
</head>
<body>   


<?php
    $comparingValues = array(); 
    $counter;



    if ($password =='password'){
        echo '<div class="alert">change the pasword!!!!!!</div>';
        return false;
    }




    $start_time = $_SESSION['start_time'] ;
    $execution_time = $_SESSION['execution_time'];

    $remaining_time = time() - $start_time + $execution_time; 
    //if we execdet the script execution time then we unset the session


    //if the sesion variable is set then we  archive the execution time and start time of the script
    if(isset($_SESSION['cleanup_in_progress'])){
        if($remaining_time <= 0){
            echo '<div class="alert">script complete,  <a href="runingScript.php" >GO here!</a>   </div>';
            unset ($_SESSION['cleanup_in_progress']);
            die;
        }                                                                 
    }



    //if the user entered all needet data we can then make the script do its work
    if(!isset($_SESSION['cleanup_in_progress']) and
    isset($_POST['DBname'],$_POST['host'],$_POST['DBusername'],$_POST['DBpassword'],$_POST['directory'],$_POST['pagePassword'],$_POST['exectutionTime'],$_POST['delayTime'],$_POST['attachment']))
    {
        echo '<div class="alert">all entered data was filed in</div><br/>';

        $_SESSION['cleanup_in_progress'] = true;
        $_SESSION['start_time'] = time();
        $_SESSION['execution_time'] = $_POST['delayTime'];
        $dir=$_POST['directory'];




        if($_POST['delayTime'] == '' and !is_int($_POST['delayTime'])){
            $delay_time = 0;   
        }else{
            $delay_time =1000 * $_POST['delayTime'];
        }                                       
        //here we seee in what value we set the execution time either in minutes or seconds 
        if($_POST['mesurment'] =='minutes'){
            $time = $_POST['exectutionTime'] * 60;   
        }else{
            $time = $_POST['exectutionTime'];
        }
        $partitoning = $_POST['partitioning']; 
        $_SESSION['partitioning'] = $partitoning;
        set_time_limit($time+15);
        $dir = $_POST['directory'];

        $finishingTIme = time() + $time;
        if(is_dir($dir)){
            $dir_content =getDirectoryContent($dir);
            $_SESSION['folderLocation']  = $dir;


            $link = mysql_connect($_POST['host'],$_POST['DBusername'],$_POST['DBpassword']) or die('<div class="alert">cant connect to mysql!!!</div>');
            mysql_select_db($_POST['DBname'],$link) or die ('<div class="alert">incorect DB name</div>');

            if ($_POST['attachment'] !==''){
                $name =  $_POST['attachment'] ;
            }else{
                $name  = 'attachment';
            }

            if(!isset($_SESSION['controlLocation'])){
                $_SESSION['controlLocation'] = 0;
            }

            echo 'the script is executing, close this page <a href="JavaScript:window.close()">Close</a> 
            </body>
            </html>';
            session_commit();
            do {
                $file = array_pop($dir_content);
                if(is_file($dir.'/'.$file)){
                    if(bufferQuerry($file)){    
                        usleep($delay_time);
                        $time = time();
                        $con = $finishingTIme - $time;
                        if ($finishingTIme <= time()){

                            storeRemainingData($dir_content);
                            session_name('cleanup');  //we set the session name
                            session_start();         
                            unset ($_SESSION['cleanup_in_progress']);
                            $host  = $_SERVER['HTTP_HOST'];
                            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
                            $extra = 'cleanupScript.php';
                            session_commit();
                            header("Location: http://$host$uri/$extra");

                            exit;
                        }
                    }else{
                        $_SESSION['eror'] = '<div class="alert">there was an folder reading eror</div>';
                        echo'<div class="alert">there was an folder reading eror</div>';
                        die;
                    }
                }
            } while ($file !== null);

            $counter = $partitoning + 5;
            bufferQuerry('none');
        }
    }


    function bufferQuerry($file){
        global $comparingValues;
        global $counter;
        global $partitoning;
        global $link;
        if ($partitoning <= $counter){
            $counter = 0;
            $sql ="SELECT `filename`  FROM  `attachment`  WHERE";
            foreach($comparingValues as $name){
                $sql.= " `filename` = '$name' or ";
            }
            $sql =  trim($sql,' or');
            $result =  mysql_query($sql,$link);
            if ($result){
                return checkResultsOfTheQuery($result);
            }else return false;
        } else {
            $counter++ ;
            $comparingValues[] = $file;
            return true;
        }
    }
    function checkResultsOfTheQuery($resultSql){
        global $comparingValues;

        if(!$resultSql) return false;
        $result = array();
        if(mysql_num_rows($resultSql)){
            foreach (mysql_fetch_array($resultSql) as $row){
                $result[] = $row;
            }
        }else{
            $result = array();
        } 


        $diference = array_diff($comparingValues,$result);
        $comparingValues = array();

        if($diference){
            return MissingFIle($diference);
        } else return true;


    }
    function MissingFIle($files){

        $option = $_POST['delete'];
        $moveFolder = $_POST['movingFolder'];
        $originalFolder = $_POST['directory'];

        if(!is_dir($moveFolder)){
            $_SESSION['eror'] ='<div class="alert">The specified rouge folder is not a folder</div>';
            echo '<div class="alert">The specified rouge folder is not a folder</div>';
            die;
        }

        if(!is_writable($moveFolder)){
            $_SESSION['eror'] ='<div class="alert">cant write to the rouge files folder</div>';
            echo '<div class="alert">cant write to the rouge files folder</div>';
            die;
        }
        if($option == 'move'){
            foreach ($files as $filename){
                rename($originalFolder.'/'.$filename, $moveFolder.'/'.$filename); 
                logDeletion($filename);

            }    
        }else{
            foreach ($files as $filename){
                unlink($originalFolder.'/'. $filename);
                logDeletion($filename);
            }
        }
        return true;
    }
    function logDeletion($file){

        $content =$file."
        " ;
        if(file_put_contents($_SERVER['SCRIPT_FILENAME'].'.log.txt',$content, FILE_APPEND)){
            return true;
        }
    }
    function storeRemainingData($handler){
        $unserialize = serialize($handler);

        $fp=fopen("dirContent.txt","w");
        $result = fwrite($fp,$unserialize);
        if($result) return true;
        else return false;
    }
    function getDirectoryContent($location){
        if($_SESSION['folderLocation'] == $location){
            if (is_file('dirContent.txt')){
                $data=file_get_contents("dirContent.txt","r");
                $array = unserialize($data);
                return $array;
            }else{
                return scandir($location,1);   
            }
        } else {
            return   scandir($location,1);
        } 

    }

?>


 

and here is runingScript.php

 

<?php

    /**
    * @copyright  at ©sinisaculic@gmail.com, all rights reserverd 2009-2010
    * @author Siniša Čulić
    * @version 1.0
    * @created 31-mar-2010 13:51:17
    */
  

    session_name('cleanup');  //we set the session name
    session_start();         //we start the session cleanup
    //$remaining_time =  $_SESSION['remaining'] ;    //set the remaining time of the script to 0 for no note sake XD
    //unset($_SESSION['cleanup_in_progress']) ;

    //here we open the log file and put it into a string

    if(is_file($_SERVER['SCRIPT_FILENAME'].'.log.txt')){
        $logFile =  file_get_contents ($_SERVER['SCRIPT_FILENAME'].'.log.txt');
    }else $logFile = 'Nothing so far';


    $start_time = $_SESSION['start_time'] ;
    $execution_time = $_SESSION['execution_time'];

    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Parameter setings</title>
        <style type="text/css">
            body{
                color:#555555;
                font-size:13px;
                background: #eeeeee;
                font-family:Arial, Helvetica, sans-serif;
                width: 100%;
                margin-left: 5%;
                margin-bottom: 12 px;
            }
            .alert{
                color: #110259;
                font-size: 4em;
                font-family: cursive;
            }
            .note{
                font-size: 0.9 em;
                color: #006;
            }
            .database_data{
                background-color: #969696;
                width: 90%;     
                padding: 12px;
                border: #808080;
                border-width: thick;
                border-style: groove;
                margin: 5px;                
                -moz-border-radius: 10px;
                -webkit-border-radius: 10px;
                border-radius: 10px
            }

            .data{
                background-color: #969696;
                width: 40%;
                padding: 12px;
                border: #808080;
                border-width: thick;
                border-style: dashed;
                margin-left: 40px; 
                -moz-border-radius: 10px;
                -webkit-border-radius: 10px;
                border-radius: 10px;
            }
            .imposible{

                background-color: #FFFFFF;
                width: 42%;
                font-size: 2em;
                padding: 12px;
                border: #808080;
                border-width: thin;
                border-style: dashed;
                margin-left: 40px;
                margin:1em;
                -moz-border-radius: 5px;
                -webkit-border-radius: 5px;
                border-radius: 5px;
                text-align: center;
            }
            .header{

                background-color: #FFFFFF;
                width: 50%;
                font-size: 2em;
                padding: 12px;
                border: #808080;
                border-width: thin;
                border-style: outset;
                margin-left: 40px;
                margin:1em;
                -moz-border-radius: 15px;
                -webkit-border-radius: 15px;
                border-radius: 15px;
                text-align: center;
                font-family: cursive;
                font-size: 4em;

            }
            .button{
                font-family: Arial, Helvetica, sans-serif;
                font-size: 3em;
            }
        </style>
    </head>
    <body>   
        <div class="header">Your personall Cleanup script X-D</div>

        <div class="data" <?php 
                if(isset($_SESSION['cleanup_in_progress'])){
                    echo  "style='display:none'";
                }
            ?>
            >
            <form action="" method="post" target="cleanupScript.php" >
                <div class="database_data"> 

                    Enter this page paswoord <br/>
                    <input type="password" class="pagePassword" name="pagePassword" value="password1"  size="38" ><br/>
                    <div class="note">Open the file in editor you will see the password CHANGE IT!!!</div>


                    Host name <input type="text" name="host" size="25" value="localhost" ><br/>

                    Database name <input type="text" name="DBname"  size="20" value="test" ><br/>

                    <div class="note">
                        <p>Enter the database name<br>
                            In which the attachment table is located</p>
                    </div>
                    <br/>

                    Database username <input type="text" name="DBusername" size="45" value="root" ><br/>

                    Database password <input type="password" name="DBpassword"  size="45" ><br/>
                    I you changed the name of the table attachment then put its name here:<br/>


                    <input type="text" size="10" name="attachment" value=""><br/>
                    <div class="note">Else LEAVE the field empty!!! </div> <br/><br/>

                    Attachment directorry<br/> <input type="text" name="directory" value="c:/test"  size="68"><br/>
                    <div class="note">Enter the directory of your attachments</div>
                </div>

                <div class="options">
                    Script execution time <input type="text" name="exectutionTime" value="10" size="5" ><br/>
                    <input type="radio"  name="mesurment" value="seconds" checked="checked">in seconds<br/> 
                    <input type="radio" name="mesurment" value="minutes">in minutes<br/> 
                    Script delay time <input type="text" name="delayTime"  size="6" ><br/>
                    <div class="note">In miliseconds</div><br/>
                    select if you want to delete or just move the invalid attachments to a folder<br/>
                    <div class="imposible">
                        <input type="radio" name="delete" value="delete">delete <br/>
                        <input type="radio" name="delete" value="move" checked="checked"> move <br/>
                    </div>
                    folder for rougue files: <input type="text" name="movingFolder" value="c:/test/New">
                    <br/>
                    input the SQL partitoning size<input type="text" name="partitioning" value="10" size="5"><br/>
                    <div class="note">this value mesures how many files at once will be compared against the Database </div>
                    <br/>
                    <br/>
                </div>
                <input type="submit" name="submit"  value="Execute the script!" class="button" />
            </form>
        </div>

        <div class="status" <?php 
                if(!isset($_SESSION['cleanup_in_progress'])){
                    echo  "style='display:none'";
                }
            ?>
            >
        Remaining time of the cleanup:<div class="big"><?php echo $remaining_time ?><div/> <br/>
            Duplicate files so far found are:<br/>

            <textarea cols="80" rows="50">  
                <?php  print_r($logFile);?>
            </textarea>          

        </div>
    </body>
    </html>

 

just create a test database with the table attachment and corresponding row, make a file on c called test and place random files in it i make endless copies of new folder.... and you can run it  can someone figure out why it wont show the progress of the files i found this

 

 

in php help

void session_write_close ( void )

 

Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.

 

i do close the session but the server wont let me access the data Q.Q

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.