Is there any way to make this code perform faster?

Posted 4 months ago by behnampmdg3

Hello;

Is there any way to make this code perform faster? Or is it as optimized as it can be.

It gets inconsistent traffic, up to 50k requests per second. So need to make it as light as possible.

<?php
include 'config.php';

if(isset($_POST['user_id']) && ctype_digit($_POST['user_id']) && 
   isset($_POST['launch_id']) && ctype_digit($_POST['launch_id']) && 
    isset($_POST['secret_key']))
    {
        $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        //Check Credentials
        $stmt = $conn->prepare("SELECT secret_key, launch_timezone FROM launch_owners INNER JOIN launch_launches ON launch_launches.user_id = launch_owners.id WHERE launch_owners.id = :id AND secret_key = :secret_key AND launch_launches.id = :launch_id");
        $stmt->bindParam(':id', $_POST['user_id']);
        $stmt->bindParam(':secret_key', $_POST['secret_key']);
        $stmt->bindParam(':launch_id', $_POST['launch_id']);
        $stmt->execute();
        if($stmt->rowCount()==1)
            {
                $result = $stmt->fetchAll();
                date_default_timezone_set($result[0]['launch_timezone']);
                //Insert record
                    $stmt = $conn->prepare("INSERT INTO launch_temp_leads (user_id, launch_id, prospect_email, time_added, date_added, source) VALUES (:user_id, :launch_id)");
                    $stmt->bindParam(':user_id', $_POST['user_id']);
                    $stmt->bindParam(':launch_id', $_POST['secret_key']);
                    $stmt->bindParam(':prospect_email', $_POST['prospect_email']);
                    $stmt->bindParam(':time_added', date('i:H'));
                    $stmt->bindParam(':date_added', date('Y-m-d'));
                    $stmt->execute();
                //Insert record    
            }
        $conn=NULL; 
    }
else 
    {
        echo "Not sufficient post data";
    }   

Thanks

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.