Skip to content

Margus Roo –

If you're inventing and pioneering, you have to be willing to be misunderstood for long periods of time

  • Cloudbreak Autoscale fix
  • Endast

php ja socketi avatud aja kontrollimine (curl)

Posted on October 25, 2010 by margusja

Nagu teada on php execute time limit ei suuda kontrollida kaua avatud socketis aega kulutatakse.

Hea võimalus ka see aeg kontrolli all hoida on kasutada PHP cURL funktsionaalsust. Ma ei hakka pikalt siin erinevadi võimalusi lahti kirjutama, täpsemaks uurimiseks on alati php manuaalida – pigem spikker endale.

Testimiseks lõin 1G faili


dd if=/dev/zero of=rand.txt bs=1M count=1024

php script

2 // Margusja's curl testscript
3
4 // create a new cURL resource
5 $ch = curl_init();
6 curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 1 ); // the maximum amount of time a socket spends on trying to connect to a host
7 curl_setopt( $ch, CURLOPT_TIMEOUT, 10 ); // the maximum amount of time a curl operation can execute for
8
9
10 // set URL and other appropriate options
11 curl_setopt($ch, CURLOPT_URL, "http://ftp.margusja.pri.ee/rand.txt");
12 curl_setopt($ch, CURLOPT_HEADER, false);
13
14 // grab URL and pass it to the browser
15 curl_exec($ch);
16
17 // close cURL resource, and free up system resources
18 curl_close($ch);

Ja tulemused erinevate väärtustega CURLOPT_TIMEOUT muutujale.
CURLOPT_TIMEOUT = 5;

[08:47:01 margusja@arendus arendus]$ time php ./curltest.php

real 0m5.063s
user 0m0.041s
sys 0m0.024s

CURLOPT_TIMEOUT = 10;

[08:47:08 margusja@arendus arendus]$ time php ./curltest.php

real 0m10.062s
user 0m0.053s
sys 0m0.096s

Posted in PHP

Post navigation

MD5 decrypt
Glusterfs

Leave a Reply

You must be logged in to post a comment.

The Master

Categories

  • Apache
  • Apple
  • Assembler
  • Audi
  • BigData
  • BMW
  • C
  • Elektroonika
  • Fun
  • Hadoop
  • help
  • Infotehnoloogia koolis
  • IOT
  • IT
  • IT eetilised
  • Java
  • Langevarjundus
  • Lapsed
  • lastekodu
  • Linux
  • M-401
  • Mac
  • Machine Learning
  • Matemaatika
  • Math
  • MSP430
  • Muusika
  • neo4j
  • openCL
  • Õpetaja identiteet ja tegevusvõimekus
  • oracle
  • PHP
  • PostgreSql
  • ProM
  • R
  • Turvalisus
  • Varia
  • Windows
Proudly powered by WordPress | Theme: micro, developed by DevriX.