草庐IT

php - mysql_fetch_object 非常慢需要大约 30 秒来加载只有 20 行

coder 2023-10-25 原文

<分区>

Possible Duplicate:
Simplest way to profile a PHP script

我们正在使用 MVC 方法构建此在线应用程序(但有点笨拙)。 应用程序的结构如下所示。

class Page{
    private $title;
    private $css;
    private $type;
    private $formData;
    private $obj;

    public function __construct($type){
        //this instance variable is designed to set form data which will appear on the pages
        $this->formData = array();
        $this->setup($type);

    }

    public function setTitle($var){
        $this->title = 'Page : ';
        $this->title .= $var;
    }

    public function getFormData() {
        return $this->formData;
    }


    private function setFormData($tmpObjs) {
        $finData = array();

        foreach($tmpObjs as $value){
            if($value == $this->obj && isset($_GET['new']))
                $newValue = 'true';
            else
            $newValue = 'false';

            $tmpData = array();
            $tmpData = $value->getData($newValue);
            $finData = array_merge($finData, $tmpData);

        }
        return $finData;
    }

    public function getTitle(){
        return $this->title;
    }

    public function displayCSS($_SESSION){
        $GlobalConfig = $_SESSION['Config'];

        $CSS = array();
        $CSS = $GlobalConfig->getCSS();

        $SIZE = count($CSS);

        foreach($CSS as $key => $value){
            echo "<link href=\"".$CSS[$key]."\" type=\"text/css\" rel=\"stylesheet\" />\n";
        }
    }

    public function displayJS($_SESSION){
        $GlobalConfig = $_SESSION['Config'];

        $JS = array();
        $JS = $GlobalConfig->getJS();

        $SIZE = count($JS);

        foreach($JS as $key => $value){
            echo "<script src=\"".$JS[$key]."\" type=\"text/javascript\"></script>\n";
        }
    }

    function setPageType($type)
    {
    $this->type = $type;
    }

    // This is used when you are filtering whatever type for search function

    function getPageType(){
    $type = $this->type;
    echo $type;
    }


    function setup($type){
        $this->type = $type;
        switch($this->type){

            case "AccountExpiry":

            break;

            case "Home":
                $CalendarExpiryItemList = new CalendarExpiryItemList();
                $CalendarExpiryItemList->createList();

                $_SESSION['Active_Form'] = 'homepage-record';
                $this->obj = $CalendarExpiryItemList;

                $objs = array($CalendarExpiryItemList);
                $this->formData = $this->setFormData($objs);

                $this->setTitle('Home');

            break;        
        }
    }

    function generateJS(){
        if(file_exists('../classes/Javascript.class.php'))
            include_once '../classes/Javascript.class.php';

        $JSType = str_replace(" " , "", ucwords(str_replace("-", " ", substr(end(explode("/", $_GET['page'])), 0, -4))));
        $JSType = $_GET['page'];

        if(substr($JSType, -1) == 's')
             $JSType = substr ($JSType, 0, -1);

        echo $JSType;
        $new_obj_name = $JSType . "JS";

        $jsObj = new $new_obj_name($this->type);        
    }


    function getObject(){
        return $this->obj;
    }

    //There is more code, file has been omitted for forum
}

下面是CalendarExpiryItemList类

class CalendarExpiryItemList
{
    private $List = array();

    public function __construct()
    {
        //Nothing To Do Yet
    }

    public function createList($Type = "Followups")
    {
        switch($Type)
        {
          case "ALL":
             $this->List = array();
             $this->getAllItemsInArray();
             return $this->List;
          break;

          case "Invoice":
            $this->List = array();
            $this->getInvoiceCalendarItems();
            return $this->List;
          break;

          case "Followups":
            $this->List = array();
            $this->getFollowUpExpiryItems();
            return $this->List;
          break;
        }
    }

    public function _compare($m, $n)
    {
        if (strtotime($m->getExpiryDate()) == strtotime($n->getExpiryDate()))
        {
            return 0;
        }

        $value =  (strtotime($m->getExpiryDate()) < strtotime($n->getExpiryDate())) ? -1 : 1;

        echo "This is the comparison value" . $value. "<br/>";

        return $value;
    }

    public function display()
    {
        foreach($this->List as $CalendarItem)
        {
            echo "<tr>";
                if($CalendarItem->getType() != "ContractorInsurance")
                    echo "<td>".DateFormat::toAus($CalendarItem->getExpiryDate())."</td>";
                else
                    echo "<td>".$CalendarItem->getExpiryDate()."</td>";
                echo "<td>".$CalendarItem->getType()."</td>";
                echo "<td>".$CalendarItem->getDescription()."</td>";
                echo "<td>".$CalendarItem->doAction()."</td>";
            echo "</tr>";
        }
    }

    public function getData()
    {
        $data = array();
        $data['Rows'] = "";
        $TempArray1 = array();

        foreach($this->List as $CalendarItem)
        {
            $Temp = "";
            $Temp .= "<tr>";
                if($CalendarItem->getType() != "ContractorInsurance")
                     $Temp .= "<td>".DateFormat::toAus($CalendarItem->getExpiryDate())."</td>";
                else
                    $Temp .= "<td>".$CalendarItem->getExpiryDate()."</td>";
                $Temp .= "<td>".$CalendarItem->getType()."</td>";
                $Temp .= "<td>".$CalendarItem->getDescription()."</td>";
                $Temp .= "<td>".$CalendarItem->doAction()."</td>";
            $Temp .= "</tr>";
            $TempArray1[] = $Temp;
        }

        if(count($TempArray1) == 0)
        {
            $Row = "<tr><td colspan='4'>No Items overdue</td></tr>";
            $TempArray1[] = $Row;
        } 

        $data['Rows'] = $TempArray1;
        return $data;

    }

    //---------------Private Functions----------------
    private function SortArrayDate()
    {
        $TempArray = array();
        $TempArray = $this->List;

        $this->List = array();

        foreach($TempArray as $CalendarItem)
        {
            $this->List[$CalendarItem->getExpiryDate()] = $CalendarItem;
        }

        ksort($this->List);

    }

    private function getAllItemsInArray()
    {
        $this->getInvoiceCalendarItems();
        $this->getFollowUpExpiryItems();
        $this->getProjectExpiryItems();
        $this->getVehicleExpiryItems();
        $this->getUserInsuranceExpiryItems();
        $this->getContractorExpiryItems();

        //$this->SortArrayDate();
    }

    private function getContractorExpiryItems()
    {
        $SQL = "SELECT * FROM  `contractor_Details` WHERE  `owner_id` =".$_SESSION['user_id'];

        $RESULT = mysql_query($SQL);

        while($row = mysql_fetch_object($RESULT))
        {
            $InsLic = new ContractorInsLis();
            $InsLic->getContractorInsLisById($row->contractor_id);

            if($InsLic->CheckExpiry($InsLic->getwcic_expiry_date()) == 'Expired')
            {
                $ContractorExpiryItem = new ContractorInsuranceExpiryItem($row->contractor_id,$InsLic->getwcic_expiry_date(),"Contractor ".$row->first_name." ".$row->last_name."'s Workers Comp License expired on ".$InsLic->getwcic_expiry_date());
                $this->List[] = $ContractorExpiryItem;
            }

            if($InsLic->CheckExpiry($InsLic->getpli_expiry_date()) == 'Expired')
            {
                $ContractorExpiryItem = new ContractorInsuranceExpiryItem($row->contractor_id,$InsLic->getpli_expiry_date(),"Contractor ".$row->first_name." ".$row->last_name."'s Public Liability Insurance expired on ".$InsLic->getpli_expiry_date());
                $this->List[] = $ContractorExpiryItem;
            }

            if($InsLic->CheckExpiry($InsLic->getcontractor_expiry_date()) == 'Expired')
            {
                $ContractorExpiryItem = new ContractorInsuranceExpiryItem($row->contractor_id,$InsLic->getcontractor_expiry_date(),"Contractor ".$row->first_name." ".$row->last_name."'s Contractor License expired on ".$InsLic->getcontractor_expiry_date());
                $this->List[] = $ContractorExpiryItem;
            }

            if($InsLic->CheckExpiry($InsLic->getwcic_expiry_date()) == 'Expired')
            {
                $ContractorExpiryItem = new ContractorInsuranceExpiryItem($row->contractor_id,$InsLic->getcompany_expiry_date(),"Contractor ".$row->first_name." ".$row->last_name."'s Company License expired on ".$InsLic->getcompany_expiry_date());
                $this->List[] = $ContractorExpiryItem;
            }
        }
    }

    private function getUserInsuranceExpiryItems()
    {
        $SQL = "SELECT * FROM `user_my_insurances_licences` WHERE `user_id`=".$_SESSION['user_id'];
        $RESULT = mysql_query($SQL);

        while($row = mysql_fetch_object($RESULT))
        {
            $UserInsuranceLicenses = new UserMyLicenseInsurance();
            if($UserInsuranceLicenses->CheckExpiry($row->DL_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->DL_expiry_date,"DL #".$row->DL_number." has expired on ".$row->DL_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->CL_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->CL_expiry_date,"CL #".$row->CL_number." has expired on ".$row->CL_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->BL_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->BL_expiry_date,"BL #".$row->BL_number." has expired on ".$row->DL_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->wcic_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->wcic_expiry_date,"Workers Compe #".$row->wcic_policy_number." has expired on ".$row->wcic_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->pli_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->pli_expiry_date,"Public Liability #".$row->pli_policy_number." has expired on ".$row->pli_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->cwi_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->cwi_expiry_date,"Contract Worker Insurance #".$row->cwi_policy_number." has expired on ".$row->cwi_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->hoi_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->hoi_expiry_date,"Home Owners Insurance #".$row->hoi_policy_number." has expired on ".$row->hoi_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->pii_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->pii_expiry_date,"Professional Indemnity Owners Insurance #".$row->pii_policy_number." has expired on ".$row->pii_expiry_date);
                $this->List[] = $ExpiredItem;
            }

            if($UserInsuranceLicenses->CheckExpiry($row->tic_expiry_date) == 'Expired')
            {
                $ExpiredItem = new UserInsuranceExpiryItem($_SESSION['user_id'],$row->tic_expiry_date,"Tools Insurance #".$row->tic_policy_number." has expired on ".$row->tic_expiry_date);
                $this->List[] = $ExpiredItem;
            }
        }
    }

    private function getVehicleExpiryItems()
    {
        $SQL = "SELECT * FROM  `user_my_motor_vehicles` WHERE  `user_id` =".$_SESSION['user_id'];
        $RESULT = mysql_query($SQL);

        while($row = mysql_fetch_object($RESULT))
        {
            $UserMotorVehicles = new UserMotorVehicles();
            if($UserMotorVehicles->CheckExpiry($row->vehicle_registration_expiry_date) == 'Expired')
            {
                $VehicleRegistration = new VehicleExpiryItem($row->id,$row->vehicle_registration_expiry_date,"Vehicle ".$row->vehicle_reg_no." Registration Expired on ".$row->vehicle_registration_expiry_date);
                $this->List[] = $VehicleRegistration;
            }

            if($UserMotorVehicles->CheckExpiry($row->insurance_expiry_date) == 'Expired')
            {

                $VehicleInsurance = new VehicleExpiryItem($row->id,$row->insurance_expiry_date,"Vehicle ".$row->vehicle_reg_no." Insurace Expired on ".$row->insurance_expiry_date);
                $this->List[] = $VehicleInsurance;
            } 
        }
    }

    private function getProjectExpiryItems()
    {
        $SQL = "SELECT * FROM my_project WHERE user_id =".$_SESSION['user_id']." AND ((end_date < '".date('Y-m-d')."') OR (end_date = '".date('Y-m-d')."') OR end_date='0000-00-00') AND (actual_end_date = '' OR actual_end_date = ' ' OR actual_end_date = '0000-00-00')";

        $RESULT = mysql_query($SQL);

        while($row = mysql_fetch_object($RESULT))
        {
            $Project = new ProjectExpiryItem($row->project_id,$row->end_date,"Project ".$row->project_name." was due on ".$row->end_date,$row->start_date);
            $this->List[] = $Project;

        }
    }

    private function getInvoiceCalendarItems()
    {
        $SQL = "SELECT * FROM project_invoices WHERE (dueDate < '".date('Y-m-d')."') AND (date_paid ='0000-00-00' OR date_paid='') AND (user_id = ".$_SESSION['user_id'].") LIMIT 0, 10";
        $RESULT = mysql_query($SQL);

        while($row = mysql_fetch_object($RESULT))
        {
            $Invoice = new InvoiceExpiryItem($row->id,$row->invoice_date,"Invoice #".$row->id." is overdue.");
            //testObj(array($Invoice));
            $this->List[] = $Invoice;
        }
    }

    private function getFollowUpExpiryItems()
    {
        $SQL = "SELECT * from followUps WHERE owner_id=".$_SESSION['user_id']." AND ((Date_Due < '".date('Y-m-d')."') OR (Date_Due = '".date('Y-m-d')."') OR (Date_Due = '0000-00-00')) AND Completed != '1'";
        $RESULT = mysql_query($SQL);

        while($row =  mysql_fetch_object($RESULT))
        {
            $Form_Id = new FormId();
            $Description = "Follow Up on ".$Form_Id->getFormNam($row->Form_id)." was due on ".$row->Date_Due;
            $FollowUp = new FollowUpExpiryItem($row->Id,$row->Date_Due,$Description);
            $this->List[] = $FollowUp;
        }
    }

这是分页类

<?php

class Pagination {
    protected $Items = array();
    protected $Type = "default";
    protected $Title = "List of ";
    protected $Base_Url = "";
    protected $Table;

    //-------------------------Table Settings----------------//
    protected $No_Of_Columns = NULL;
    protected $No_Of_Items_Per_Page = 10; //By Default 10 items will be displayed on a page.protected
    protected $Present_Page = 0;
    protected $Columns = array();
    protected $Rows = array();

    //------------------------Table Class Attributes---------//
    protected $Table_Class = "";
    protected $Table_Id = "";
    protected $GETVarName = "PP";

    /**
     *
     */
    public function __construct()
    {
        $this->Table = false;
    }

    public function paginate()
    {
        //Check if the base url is set
        if(strlen($this->Base_Url) == 0){
            echo "Error: Could not paginate, No base url Found!";
        }

        //Set the Current page value to Present Page
        if(isset($_GET))
        {
            if(isset($_GET[$this->GETVarName])){
                $this->Present_Page = intval($_GET[$this->GETVarName]);
            } else {
                $this->Present_Page = 1;
            }
        }

        //Draw the table and the values
        $this->generatePaginationTable();
    }

    public function setData($data)
    {
        if(is_array($data)){
            $this->Rows = $data;
            return true;
        } else {
            return false;
        }
    }

    public function putData($object,$functionName = "generateRow")
    {
        $TempData = array();
        if(method_exists($object,"getObjs"))
        {
            $ObjectArray = $object->getObjs();
        }

        if(method_exists($object,$functionName))
        {
            foreach($ObjectArray as $Obj)
            {
                $TempData[] = $object->$functionName($Obj);
            }
        }

        $this->setData($TempData);
        unset($TempData);
    }

    public function setIsTable($val)
    {
        $this->IsTable = $val;
    }

    public function addColumnNames($Col){
        if(is_array($Col)){
            $this->No_Of_Columns = $Col;
        } else {
            return false;
        }
    }

    /**
     * @param $config (array)
     * @return bool
     *
     * this function initializes the Pagination object with the
     * initial values
     */
    public function initialize($config)
    {
        if(is_array($config))
        {
            foreach($config as $key => $value)
            {
                if(isset($this->$key))
                {
                    $this->$key = $value;
                } 
            }
        } else if(is_object($config)) {
            return false;
        } else if(is_string($config)){
            return false;
        }
    }


    //------------------------------Private Function For the Class-------------------------//
    private function generatePaginationTable()
    {
        if($this->Table){
            $this->StartTable();
            $this->DisplayHeader();
        }

        $this->DisplayData();
        $this->DisplayLinks();

        if($this->Table)
            echo "</table>";
    }

    private function DisplayLinks()
    {
        if($this->Table){
        echo "<tr>";
        echo '<td colspan="'. count($this->Rows) .'">';
            $this->GenerateLinkCounting();
        echo '</td>';
        echo "</tr>";
        } else {
            if(count($this->Rows) > 0)
            {
                $ROW = $this->Rows[0];
                $ColSpan = substr_count($ROW,"<td");

                 echo "<tr>";
                echo '<td colspan="'. $ColSpan .'" align="right">';
                $this->GenerateLinkCounting();
                echo '</td>';
                echo "</tr>";
            }
        }
    }

    private function GenerateLinkCounting()
    {
        $this->Base_Url .= $this->getOtherGetVar();
        $StartCount = 1;
        $EndCount = count($this->Rows) / $this->No_Of_Items_Per_Page;

        for($i=0; $i < $EndCount; $i++)
        {
            if($i == 0)
            {
                echo ' <a href="'. $this->Base_Url.'&'.$this->GETVarName .'='.intval($i+1). '" >First</a> ';
            } else if($i == intval($EndCount)){
                echo ' <a href="'. $this->Base_Url.'&'.$this->GETVarName .'='.intval($i+1).'" >Last</a> ';
            } else {
                echo ' <a href="'. $this->Base_Url.'&'.$this->GETVarName .'='.intval($i+1). '" >'.intval($i+1).'</a> ';
            }

        }
    }

    private function getOtherGetVar()
    {
        $Link = "";
        if(isset($_GET))
        {
            foreach($_GET as $key => $val)
            {
                if($key != $this->GETVarName)
                {
                   $Link .= "&".$key."=".$val;
                }
            }
        }

        $h = preg_split("/&/",$this->Base_Url);

        $this->Base_Url = $h[0];
        return $Link;
    }

    private function DisplayData()
    {
        $Index = 0;
        $StartIndex = intval(intval($this->Present_Page-1) * $this->No_Of_Items_Per_Page);


        $EndIndex = intval($StartIndex + $this->No_Of_Items_Per_Page);
        foreach($this->Rows as $Row)
        {
            $Index++;
            if($Index >= $StartIndex && $Index <= $EndIndex)
            {
                echo "<tr>";
                    if(is_array($Row))
                    {
                        foreach($Row as $key => $value){
                            echo "<td>".$value."</td>";
                        }
                    } else {
                        echo $Row;
                    }

                echo "</tr>";
            } 
        }
    }

    private function DisplayHeader()
    {
        if(is_array($this->Columns))
        {
            echo "<thead>";
                echo "<tr>";

                foreach($this->Columns as $Col => $value)
                {
                    echo "<td>".$value."</td>";
                }

                echo "</tr>";
            echo "</thead>";
        }
    }

    private function StartTable()
    {
        echo "<table ";
        if(strlen($this->Table_Class) > 0)
                echo 'class="'.$this->Table_Class.'" ';

        if(strlen($this->Table_Id) > 0)
                echo 'id="'.$this->Table_Id.'" ';

        echo ">";
    }


}

文件的最终实现

<?php
$Page = new Page('Home');

$data = $Page->getFormData();

$Pagination = new Pagination();

$config = array();
$config['Table'] = false;
$config['No_Of_Items_Per_Page'] = 25;
$config['Base_Url'] = base_url() . 'BootLoader.php?page=Homepage';
$config['GETVarName'] = "ODL";

$Pagination->initialize($config);
$Pagination->setData($data['Rows']);



/**
 * Want to have multiple lists
 */

$CalendarExpiryList = $Page->getObject();

$CalendarExpiryList->createList("Invoice");

$InvoiceList = new Pagination();

$config = array();
$config['Table'] = false;
$config['No_Of_Items_Per_Page'] = 25;
$config['Base_Url'] = base_url() . 'BootLoader.php?page=Homepage';
$config['GETVarName'] = "OIDL";

$InvoiceList->initialize($config);

$data2 = $CalendarExpiryList->getData();
$InvoiceList->setData($data2['Rows']);

//This is the display
include_once("Forms/homepage/home-page.html.php");

?>

PHP 脚本运行良好。加载大约需要0.03。 但是当脚本到达 CalendarExpiryItemList 类时。大约需要 30 秒,我的服务器超时。

每个表平均有大约 12 到 15 个字段和大约 10 到 100 条记录。

我正在托管一家托管公司,他们有负载均衡器。因此,如果我的脚本花费的时间超过 30 秒,负载均衡器会重置我的连接并返回一条错误消息“服务器未发送数据”

有关php - mysql_fetch_object 非常慢需要大约 30 秒来加载只有 20 行的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  3. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  4. 使用canal同步MySQL数据到ES - 2

    文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co

  5. kvm虚拟机安装centos7基于ubuntu20.04系统 - 2

    需求:要创建虚拟机,就需要给他提供一个虚拟的磁盘,我们就在/opt目录下创建一个10G大小的raw格式的虚拟磁盘CentOS-7-x86_64.raw命令格式:qemu-imgcreate-f磁盘格式磁盘名称磁盘大小qemu-imgcreate-f磁盘格式-o?1.创建磁盘qemu-imgcreate-fraw/opt/CentOS-7-x86_64.raw10G执行效果#ls/opt/CentOS-7-x86_64.raw2.安装虚拟机使用virt-install命令,基于我们提供的系统镜像和虚拟磁盘来创建一个虚拟机,另外在创建虚拟机之前,提前打开vnc客户端,在创建虚拟机的时候,通过vnc

  6. 牛客网专项练习30天Pytnon篇第02天 - 2

    1.在Python3中,下列关于数学运算结果正确的是:(B)a=10b=3print(a//b)print(a%b)print(a/b)A.3,3,3.3333...B.3,1,3.3333...C.3.3333...,3.3333...,3D.3.3333...,1,3.3333...解析:    在Python中,//表示地板除(向下取整),%表示取余,/表示除(Python2向下取整返回3)2.如下程序Python2会打印多少个数:(D)k=1000whilek>1:    print(k)k=k/2A.1000 B.10C.11D.9解析:    按照题意每次循环K/2,直到K值小于等

  7. ruby-on-rails - 使用 HTTParty 的非常基本的 Rails 4.1 API 调用 - 2

    Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"

  8. objective-c - 在设置 Cocoa Pods 和安装 Ruby 更新时出错 - 2

    我正在尝试为我的iOS应用程序设置cocoapods但是当我执行命令时:sudogemupdate--system我收到错误消息:当前已安装最新版本。中止。当我进入cocoapods的下一步时:sudogeminstallcocoapods我在MacOS10.8.5上遇到错误:ERROR:Errorinstallingcocoapods:cocoapods-trunkrequiresRubyversion>=2.0.0.我在MacOS10.9.4上尝试了同样的操作,但出现错误:ERROR:Couldnotfindavalidgem'cocoapods'(>=0),hereiswhy:U

  9. ruby - 你会如何在 Ruby 中表达成语 "with this object, if it exists, do this"? - 2

    在Ruby(尤其是Rails)中,您经常需要检查某物是否存在,然后对其执行操作,例如:if@objects.any?puts"Wehavetheseobjects:"@objects.each{|o|puts"hello:#{o}"end这是最短的,一切都很好,但是如果你有@objects.some_association.something.hit_database.process而不是@objects呢?我将不得不在if表达式中重复两次,如果我不知道实现细节并且方法调用很昂贵怎么办?显而易见的选择是创建一个变量,然后测试它,然后处理它,但是你必须想出一个变量名(呃),它也会在内存中

  10. ruby-on-rails - 无法安装 mysql2 0.3.14 gem - 2

    我看到其他人也遇到过类似的问题,但没有一个解决方案对我有用。0.3.14gem与其他gem文件一起存在。我已经完全按照此处指示完成了所有操作:https://github.com/brianmario/mysql2.我仍然得到以下信息。我不知道为什么安装程序指示它找不到include目录,因为我已经检查过它存在。thread.h文件存在,但不在ruby​​目录中。相反,它在这里:C:\RailsInstaller\DevKit\lib\perl5\5.8\msys\CORE\我正在运行Windows7并尝试在Aptana3中构建我的Rails项目。我的Ruby是1.9.3。$gemin

随机推荐