php curl 也可以這樣用
php curl 也可以這樣用 @ 不大會寫程式 :: 隨意窩 Xuite日誌
今天和同事討論一個監控的問題, 發覺 CURL 原來也可以這樣來用, CURL 可以透過 curl_getinfo 來把連線過程中, 一些數據詳細的記錄下來, 裏面有幾個時間的值, 可以當做監控服務的回應時間, 大家可以參考看看 是個滿有趣的作法 http://docs.cacti.net/usertemplate:graph:curl_bwtest_response_timeCURLINFO_TOTAL_TIME – Total transaction time in seconds for last transfer
CURLINFO_NAMELOOKUP_TIME – Time in seconds until name resolving was complete
CURLINFO_CONNECT_TIME – Time in seconds it took to establish the connection
CURLINFO_PRETRANSFER_TIME – Time in seconds from start until just before file transfer begins
CURLINFO_STARTTRANSFER_TIME – Time in seconds until the first byte is about to be transferred
CURLINFO_REDIRECT_TIME – Time in seconds of all redirection steps before final transaction was started大家可以簡單寫支程式, 看看這些數據的變化
<!–?php
// Create a curl handle
$url = $argv[1];
$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, ‘Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Foxy/1; Foxy/1; .NET CLR 2.0.50727)’);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_COOKIEJAR, ‘/tmp/cookie.txt’);
curl_setopt ($ch, CURLOPT_COOKIEFILE, ‘/tmp/cookie.txt’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array(‘Expect:’));
$store = curl_exec ($ch);// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
print_r($info);echo ‘Took ‘ . $info[‘total_time’] . ‘ seconds to send a request to ‘ . $info[‘url’] . “\n";
}// Close handle
curl_close($ch);
?>跑了之後發現同樣設定的幾組伺服器, CURLINFO_STARTTRANSFER_TIME, CURLINFO_PRETRANSFER_TIME 這兩個數值差了滿多的, 不知道在這兩個數據相減後, 這其間的時候 server 在做什麼 ?? 有幾組伺服器這個 delta 滿大的, 該怎麼消減他才好呢 ?? 看起來和 loading 也無關, 因為找了一台把他從 SLB 切開後, 這個數值並沒有很顯著的變化 !!
Use Orbit Downloader as RTMP Recorder
Use Orbit Downloader as RTMP RecorderHow to Record RTMP Media, Video and Music? RTMP is a protocol used by flash to deliver real time media, video, and music. Orbit Downloader is a free RTMP Recorder which can help you to record RTMP media, video and music from sites which are using RTMP potocol include Yahoo, Youtube, Finetune … easily with great speed.
SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 17 of 31
SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 17 of 31
SQL SERVER – Recompile All The Stored Procedure on Specific Table
SQL SERVER – Recompile All The Stored Procedure on Specific Table « Journey to SQLAuthority
SQL SERVER – Recompile All The Stored Procedure on Specific TableJune 29, 2007 by pinaldave
I have noticed that after inserting many rows in one table many times the stored procedure on that table executes slower or degrades. This happens quite often after BCP or DTS. I prefer to recompile all the stored procedure on the table, which has faced mass insert or update. sp_recompiles marks stored procedures to recompile when they execute next time.
Example:
—-Following script will recompile all the stored procedure on table Sales.Customer in AdventureWorks database.
USE AdventureWorks;
GO
EXEC sp_recompile N’Sales.Customer’;
GO
—-Following script will recompile specific stored procedure uspGetBillOfMaterials only.
USE AdventureWorks;
GO
EXEC sp_recompile ‘uspGetBillOfMaterials’;
How to Kill MySQL Sleeping Connections in C# ASP .NET
Primary Objects – How to Kill MySQL Sleeping Connections in C# ASP .NET
How to Kill MySQL Sleeping Connections in C# ASP .NET
CAPTCHA in php
TSQL String Array Workbench
TSQL String Array Workbench
STARTUP/SHUTDOWN Oracle database via .BAT file and SVRMGRL
STARTUP/SHUTDOWN Oracle database via .BAT file and SVRMGRL – dBforums
Set it up as a .BAT file and run it in the AT scheduler…submit a job to the scheduler that does …
svrmgrl @filename
the above file should look something like …
set instance instancename
connect internal/password@instancename
shutdown immediate … (or whatever you are looking to do)
exit
DOS command for ‘Wait 5 seconds…’
DOS command for ‘Wait 5 seconds…’
I came up with a somewhat odd way of waiting for a specified amount of time the other day when writing a batch file.First, it requires the PING tool, so I don’t know if it will work very well for you, but it’s worth a shot.
Use it like this if you want to wait 5 seconds with no output:
PING 1.1.1.1 /N 3 /W 1000 > NUL
The general rule that seems to be pretty accurate is to divide the number of seconds to wait by 2 and use that value for the /N switch. This example is for 5 seconds, so you use use /N 3 to get pretty close to 5 secs (about 5.3 secs on my system).