3

I have created a script to check in backup tapes into our tape library and check them in with TSM. This script is activated by SMS.

Our SMS server receives the command to start the check-in and then executes a script on the TSM server with a file_get_contents command.

I have an issue that the script is being executed twice when there are allot of tapes to check in(+20). This results errors on out TSM server because the move media commands are allso double.

I overcame this by putting in an inital timestamp logging when the first file_get_content is started so the commands arent executed twice. Allthough this fixes the double command issue it still presents a problem because the SMS server sends back confirmation that the script started or not. So this means that on every check in with +20 tapes, the operator gets 2 messages, 1 saying check in failed, the other check in started.

I suspect this is caused because of the time it takes for the commands to be passed onto the TSM server (can take upto 45seconds).

Long story short, is there a way i can set some sort of longer timeout, or give any parameter/checks to prevent this behaviour? Thanks in advance. Paths are replaced by *****.

SMS server code
    //DRM checkin
            if($auth == 1 AND strtolower($sms_body) == "******"){
                $knowncommand = 1;
                $url = "http://*******/******/checkin.php?remote&exec&sender=" . $from;
                $dodrm = file_get_contents($url);
                if ($stmt2 = $mysqli->prepare("UPDATE messagein SET checked = 1 WHERE checked = 0 ")) {
                    $stmt2->execute();
                    $stmt2->close();
                }
            }

TSM Server script code:

if(isset($_GET['exec'])){
    if(isset($_GET['remote'])){
        $rcs = CheckRemoteCheckinStatus();
        $to = $_GET['sender'];
        //Execute drm check-in
        $commit = CheckButtonStatus();
        if($commit == "" AND $rcs == 0){
            SetRemoteCheckinStatus();
            $psDIR = "*****";
            $psScript = "drm_checkin_retrieve.ps1";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
            SetCheckinStatus();
            $psDIR = "*****";
            $psScript = "QueueSMS.ps1 $to 'Check-in gestart...'";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
        }
        else{
            //Send Failed SMS
            $psDIR = "*****";
            $psScript = "QueueSMS.ps1 $to 'Fout: Geen Check-in mogelijk.'";
            $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
            exec($runCMD, $out);
        }
    }
    else{
        $psDIR = "*******";
        $psScript = "drm_checkin_retrieve.ps1";
        $runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript;
        exec($runCMD, $out);
        echo "Check-in gestart...<br><br>";
        SetCheckinStatus();
    }
}
Martin Law
  • 444
  • 1
  • 3
  • 12

2 Answers2

0

If you have access to your php.ini, this topic can be usefull

If you want to increase your timeout only in a specific script, you can use set_time_limit

Or another way, at the beginning of your php script :

ini_set('max_execution_time', 120); //120 seconds
Community
  • 1
  • 1
shabang
  • 160
  • 1
  • 13
  • Hi, thx for the tip, however the script that executes this is a command line deamon, and the standard execution time for that should allready be set to inlimited. Allso the script itsself does not seem to timeout, it just sends the file_get_contents again and then continous with the script as designed. I will however test this to see that it makes a difference. – Martin Law Aug 09 '16 at 06:50
  • I am trying with ini_set('default_socket_timeout', 900); since i expect that will have more effect. Will get back with feedback. (can only test this on mo, wed, fri) – Martin Law Aug 09 '16 at 06:55
  • 1
    Is your deamon in a while loop strategy, or called via a cron job ? Is there any chance the script is called twice is a short time ? – shabang Aug 09 '16 at 14:18
  • The deamon runs on an infinite while loop. After recieving the SMS it marks is as read in the database so that prevents from calling the script twice. This behaviour allso only occurs when there in 20+ tapes. – Martin Law Feb 01 '17 at 10:59
0

I encountered a similar problem when using file_get_contents in combination with stream_context_create to call a REST API.

For some reason, file_get_contents sometimes seems to execute calls twice (maybe for error correction). This led to duplicate items being created via the API, even if our wrapper function has been called only once.

After switching to a cURL-based implementation, the error did not occur anymore. Here's an example: https://github.com/ubtue/tuefind/pull/2270/files