Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirect holding up script

Tags:

redirect

php

UPDATE

I found the issue that was holding up my script. Apparently it had nothing to do with decryption, but my redirect instead. When I removed this block of code, the script starting performing quickly. Still not sure why this was causing the issue?

// Make sure we have an Order ID
if( ! isset($_GET['id']) && ! isset($_POST['id']) ) {
    header("Location: https://www.website.com/orders/");
    exit;
}

ORIGINAL QUESTION:

I have been using the Encryption class found here: Encryption class. I am storing the data in a MySQL database, with a VARCHAR binary data type (formerly I tried BLOB and TINYBLOB).

The encrypting and decrypting both work, however it takes like 1 minute to decrypt. The encryption is fast.

I guess I should also say that this is happening over a https connection (in case that's relevant).

I don't remember it always taking this long to decrypt. Do you have any idea what could be causing this? When I comment out the decryption portion of the PHP code, and just echo back the encrypted string, it performs quickly.

CODE AS REQUESTED BELOW IN THE COMMENTS

class Encryption
{
    const CYPHER = 'blowfish';
    const MODE   = 'cfb';
    const KEY    = 'MyPersonalKey';

    public function encrypt($plaintext)
    {
        $td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, self::KEY, $iv);
        $crypttext = mcrypt_generic($td, $plaintext);
        mcrypt_generic_deinit($td);
        return $iv.$crypttext;
    }

    public function decrypt($crypttext)
    {
        $plaintext = '';
        $td        = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
        $ivsize    = mcrypt_enc_get_iv_size($td);
        $iv        = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv)
        {
            mcrypt_generic_init($td, self::KEY, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }

        return $plaintext;
    }
}

Here is the code from the webpage, where I set the variables from the MySQL row. I am using WordPress' $wpdb object.

$order = $wpdb->get_row("SELECT * FROM orders WHERE id = ".$order_id." LIMIT 0,1");

$addons_price =      $order->addons_price;
$hooked_package =    (isset($_GET['hooked_package'])) ? $_GET['hooked_package'] : $order->hooked_package;
$arrival_date_unix = $order->arrival_date_unix;
$order_data =        unserialize($order->order_data);
$preview_total =     $order_data['preview_price'] + $addons_price + $order_data['travel_insurance'];
$normal_total =      $order_data['normal_price'] + $addons_price + $order_data['travel_insurance'];
$package_price =     $order->package_price;
$total_price =       $order->total_price;
$billing_cc =        Encryption::decrypt($order->billing_cc);

Also, here is the MySQL type...

`billing_cc` varbinary(255) DEFAULT NULL
like image 627
Mike McLin Avatar asked May 23 '11 16:05

Mike McLin


1 Answers

The code you indicate as being your problem is a simple conditional redirect. So it shouldn't have anything to do with the decryption. The only reason I can see for the redirect being slow is that the web server is under heavy load, on a slow connection or has some other performance issue.

like image 64
inquam Avatar answered Oct 19 '22 18:10

inquam