PHP / HTML в Safari с Mac Os 10.6.5 работает очень медленно

#php #html #macos #google-chrome #safari

#php #HTML #macos #google-chrome #safari

Вопрос:

Это скрипт:

 <?php

require_once 'swift-mailer/lib/swift_required.php';

$name = $_POST['name'];
$email = $_POST['email'];
$form_subject = $_POST['form_subject'];
$form_message = $_POST['form_message'];

if (isset($_POST['submit'])) {

        if ($_POST['name'] != "") {
            $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
            if ($_POST['name'] == "") {
                $errors .= 'Please enter a valid name.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your name.<br/>';
        }

        if ($_POST['email'] != "") {
            $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
            }
        } else {
            $errors .= 'Please enter your email address.<br/>';
        }

        if ($_POST['form_subject'] != "") {
            $form_subject = filter_var($_POST['form_subject'], FILTER_SANITIZE_STRING);
            if ($_POST['form_subject'] == "") {
                $errors .= 'Please enter a valid subject.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your subject.<br/>';
        }

        if ($_POST['form_message'] != "") {
            $form_message = filter_var($_POST['form_message'], FILTER_SANITIZE_STRING);
            if ($_POST['form_message'] == "") {
                $errors .= 'Please enter a valid comment.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your comment.<br/>';
        }


if (!$errors) {


//File upload

// Where the file is going to be placed 
$target_path = "uploads/";

// Add the original filename to our target path.  
//Result is "uploads/filename.extension" 
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename($_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}   
}
//End of file upload

//Create the Transport
$transport = Swift_MailTransport::newInstance();

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create the message
$message = Swift_Message::newInstance();

  //Give the message a subject
$message->setSubject('New data submitted');

$ip=$_SERVER['REMOTE_ADDR'];
$date=date("l, F j, Y, g:i a");

  //Give it a body
$message->setBody("Here is the information submitted to 
www.polycysticliverdisease.com/html/contact_email.php 
from $ip on $date.nn
--------------------------------nn
name: $name nn
email address: $email nn
subject: $form_subject nn
comment: $form_message");

  //Add alternative parts with addPart()
//$message->addPart('My amazing body in plain text', 'text/plain');

//Create the attachment
// * Note that you can technically leave the content-type parameter out
$attachment = Swift_Attachment::fromPath($target_path);  

//Attach it to the message
$message->attach($attachment);

//Using setTo() to set all recipients in one go
$message->setTo(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Diane Smith'));

//Set a From: address including a name
$message->setFrom(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Contact Us'));

//Send the message
$numSent = $mailer->send($message);

//printf("Sent %d messagesn", $numSent);

if(isset($_FILES['uploadedfile'])){
$pathfile = "/home/vitusya/eximi.dreamhosters.com/Hawaii/html/uploads/" . $_FILES['uploadedfile']['name'];
@unlink($pathfile);
}

$to = "$email";
$subject = "Thank You!";
$body = "Thank you for e-mailing us.  We will reply as soon as possible.";
mail($to, $subject, $body);

        }


        else {
            echo '<div style="color: red">' . $errors . '<br/>
                </div>';



        }
    }



?> 
  

Это форма:

     <form name="contact" action="contact_email.php" method="POST" enctype="multipart/form-data">
        <table>
            <tr>
                <td>
                    <h2 class="lower">Contact Us</h2>
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="name">Your Name:</label><br />
                    <input class="text" type="text" name="name" />
                    <br />
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="email">Your E-Mail Address:</label><br />
                    <input class="text" type="text" name="email" />
                    <br />
                </td>   
            </tr>
            <tr>
                <td class="pretty_border">
                    <label for="form_subject">Subject:</label><br />
                    <input class="text" type="text" name="form_subject" />
                    <br />
                </td>   
            </tr>
            <tr>    
                <td class="textarea_border">
                    <label for="form_message">Your Message:</label><br />
                    <textarea rows="7" cols="50" name="form_message"></textarea>
                    <br />
                </td>   
            </tr>
            <tr>    
                <td>
                    <div class="fileinputs">
                        <input type="submit" class="file" name="submit" />
                        <div class="fakefile">
                                <img src="../assets/images/submit_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="file" class="file" name="uploadedfile" />
                        <div class="fakefile">
                                <img src="../assets/images/uf_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="reset" class="file" />
                        <div class="fakefile">
                                <img src="../assets/images/reset_btt.png" />
                        </div>
                    </div>
                    <div class="fileinputs">
                        <input type="button" class="file" onclick="window.print()" />
                        <div class="fakefile">
                                <img src="../assets/images/print_btt.png" />
                        </div>                      
                    </div>
                </td>   
            </tr>

        </table>
        </form>
  

Все отлично работает в Windows с любым браузером, также отлично работает на iPhone и iPad.
Похоже, проблема в Mac.
Скрипт выполняется очень медленно и отправляет письмо с благодарностью пользователю с неправильного адреса электронной почты.
Также кажется, что Google Chrome на Mac имеет ту же проблему.

Как вы думаете, что это может быть?

Спасибо!

Комментарии:

1. Вы имеете в виду, что этот скрипт, запущенный на вашем Mac, выполняется медленно или что страница не работает из Safari на Mac 10.6.5?

2. Запущен ли сервер на вашем локальном компьютере Mac для целей разработки? Если это так, это добавит к списку возможных узких мест. Если это не так, найти решение будет немного проще 🙂

3. Просто используйте xdebug и профилируйте свой скрипт. (В противном случае, я предполагаю, что медлительность возникает из-за использования вами синтаксиса XHTML, но отсутствия mime-типа XHTML.)

4. Ну, я думаю, он работает медленно в любом Safari на Mac 10.6.5. Я не думаю, что это

5. Мой клиент зашел в Apple Store и протестировал его там на нескольких компьютерах.

Ответ №1:

время выполнения не имеет никакого отношения к браузеру php — это серверный язык, вы должны отладить свой код, выполнив эхо-вывод различных переменных, которые у вас есть, через скрипт и проверить, имеют ли они предполагаемое значение, если нет, вы могли бы заглянуть в код, предшествующий тому, где вы эхо-выводили переменную, чтобы найти, что могло пойти не так