Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

How can I adjust the server to run my PHP script quicker?

I have a PHP script which runs on a loop for x amount of times. The code is very minimal and performs checks. Some loops will run within 1 second of each other and it varies.. some loops will run with up to 8 seconds delay.

How or what can I adjust/tweak on the server (or instruct the manager of my dedicated server) to reduce the time between loops to milliseconds (or as quick as possible) rather than 1 to 8 seconds?

Thank you!

PHP code

<style type="text/css">
#check { font: Arial, Helvetica, sans-serif; font-size: 12px; margin-bottom: 40px; }
.red { color: #C00; }
.green { color: #060; }
</style>

<?php        date_default_timezone_set('Australia/Brisbane');   $var1 = "variable";     $var2 = 1;      $var3=="no";
                while ($var2 <= 50)     {

                        $sApiUrl = "https://www.apiurl.com/";

                        $aParams = Array(
                                    'uid'     => "user",   
                                    'pw'      => "key",    
                                    'command' => "command",     
                                    'sld'     => "main",        
                                    'tld'     => "ext");         


                        $oCurl = curl_init();
                        curl_setopt($oCurl, CURLOPT_URL, $sApiUrl);
                        curl_setopt($oCurl, CURLOPT_POST, 1);
                        curl_setopt($oCurl, CURLOPT_POSTFIELDS, $aParams);
                        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
                        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
                        $sResponse = curl_exec($oCurl);
                        curl_close($oCurl);


                        $oOutput = new SimpleXmlElement($sResponse);


                        foreach ($oOutput as $v1)
                          {  
                             foreach ($v1 as $v2)
                             { 
                                foreach ($v2 as $v3)
                                {
                                    foreach ($v3 as $v4=>$temp)
                                    {
                                         if($v4=="text")
                                            $var4 = $temp;
                                             if($var4=="true")
                                              {                                         
                                                    $aParams = Array(
                                                    'uid'     => "user",   
                                                    'pw'      => "key",  
                                                    'command' => "command",   
                                                    'sld'     => "main",       
                                                    'tld'     => "ext",
                                                    'dosomething' => "yes");    


                                                    $oCurl = curl_init();
                                                    curl_setopt($oCurl, CURLOPT_URL, $sApiUrl);
                                                    curl_setopt($oCurl, CURLOPT_POST, 1);
                                                    curl_setopt($oCurl, CURLOPT_POSTFIELDS, $aParams);
                                                    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
                                                    curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);
                                                    $sResponse = curl_exec($oCurl);
                                                    curl_close($oCurl); 

                                                    $var3=="yes";   
                                              }                           
                                    }
                                }
                             }
                          }         $checktime = date('h:i:s A');                           echo "<div id="check">$checktime, checked $var1<br>";         if ($var4=="true")          echo "<div class="green"> $var4";         else            echo "<div class="red"> $var4";
                if ($var3=="yes")           echo " and yes";    echo "</div></div>";        $var3=="no";    $loops++;   }        ?>

Processor Information

Processor #1 Vendor: GenuineIntel Processor #1 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #1 speed: 1995.120 MHz Processor #1 cache size: 6144 KB

Processor #2 Vendor: GenuineIntel Processor #2 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #2 speed: 1995.120 MHz Processor #2 cache size: 6144 KB

Processor #3 Vendor: GenuineIntel Processor #3 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #3 speed: 1995.120 MHz Processor #3 cache size: 6144 KB

Processor #4 Vendor: GenuineIntel Processor #4 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #4 speed: 1995.120 MHz Processor #4 cache size: 6144 KB

Processor #5 Vendor: GenuineIntel Processor #5 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #5 speed: 1995.120 MHz Processor #5 cache size: 6144 KB

Processor #6 Vendor: GenuineIntel Processor #6 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #6 speed: 1995.120 MHz Processor #6 cache size: 6144 KB

Processor #7 Vendor: GenuineIntel Processor #7 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #7 speed: 1995.120 MHz Processor #7 cache size: 6144 KB

Processor #8 Vendor: GenuineIntel Processor #8 Name: Intel(R) Xeon(R) CPU E5405 @ 2.00GHz Processor #8 speed: 1995.120 MHz Processor #8 cache size: 6144 KB

Memory Information

Memory for crash kernel (0x0 to 0x0) notwithin permissible range Memory: 8302344k/9175040k available (2176k kernel code, 80272k reserved, 901k data, 228k init, 7466304k highmem)

System Information

Linux server.myserver.com 2.6.18-194.17.1.el5PAE #1 SMP Wed Sep 29 13:31:51 EDT 2010 i686 i686 i386 GNU/Linux

Physical Disks

SCSI device sda: 1952448512 512-byte hdwr sectors (999654 MB) sda: Write Protect is off sda: Mode Sense: 03 00 00 08 SCSI device sda: drive cache: write back SCSI device sda: 1952448512 512-byte hdwr sectors (999654 MB) sda: Write Protect is off sda: Mode Sense: 03 00 00 08 SCSI device sda: drive cache: write back sd 0:1:0:0: Attached scsi disk sda sd 4:0:0:0: Attached scsi removable disk sdb sd 0:1:0:0: Attached scsi generic sg4 type 0 sd 4:0:0:0: Attached scsi generic sg7 type 0

Current Memory Usage

         total       used       free     shared    buffers     cached

Mem: 8306672 7887632 419040 0 508076 6496876 -/+ buffers/cache: 882680 7423992 Swap: 4095992 428 4095564 Total: 12402664 7888060 4514604

Current Disk Usage

Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 898G 200G 653G 24% / /dev/sda1 99M 19M 76M 20% /boot none 4.0G 0 4.0G 0% /dev/shm /var/tmpMnt 4.0G 161M 3.6G 5% /tmp

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do you use databases, emails, web services, or any other similar component? Generally, the performance of a PHP script is most dependent on these.

You can use a profiling tool like Xdebug to analyse your script and find the slowest areas of code. You can then optimise this code (e.g. inner loops) to improve performance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...