PECL -> HTTP Extension voor Windows ?
Ik ben er wel al mee begonnen en werkt prima, maar moet natuurlijk nog volledig uitgebouwd worden dat alle HTTP1.0 en HTTP1.1 functionaliteit er volledig in zit.
Dit is een voorbeeld van het HTTP_Responce object.
Code (php)
1
2
3
4
5
2
3
4
5
$HTML_Doc = '<HTML><BODY>Simpel documentje</BODY></HTML>';
$New_HTTP_Responce = new cHTTP_1_1_Responce($HTML_Doc);
$New_HTTP_Responce->setCacheControl(conCacheControl_NO_CASHING, conResponce_NO_CASHING);
$New_HTTP_Responce->Send();
$New_HTTP_Responce = new cHTTP_1_1_Responce($HTML_Doc);
$New_HTTP_Responce->setCacheControl(conCacheControl_NO_CASHING, conResponce_NO_CASHING);
$New_HTTP_Responce->Send();
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class cHTTP_Responce
{
private $prvHTTP_Headers;
private $prvHTTP_Responce;
public function __construct(&$aHTTP_Responce) {
$this->prvHTTP_Headers = array();
$this->prvHTTP_Responce = &$aHTTP_Responce;
}
public function addHeader($aHeader, $aHeaderData, $aReplace = true) {
if ($aReplace) { $this->prvHTTP_Headers[$aHeader] = array('Data' => $aHeaderData); }
else {
if(!isArray($this->prvHTTP_Headers[$aHeader])) {
$this->prvHTTP_Headers[$aHeader] = array();
$this->prvHTTP_Headers[$aHeader]['Replace'] = True;
$ID = count($this->prvHTTP_Headers[$aHeader]['Data']);
$this->prvHTTP_Headers[$aHeader]['Data'][$ID] = $aHeaderData;
}
}
}
public function getData()
{ return $this->prvHTTP_Responce;
}
public function Send()
{
$this->SendHeaders();
echo $this->prvHTTP_Responce; // Beetje buggy !
return True;
}
private function SendHeaders()
{
foreach ($this->prvHTTP_Headers as $HeaderName => $Header) {
if( (array_key_exists('Replace', $Header)) & ($Header['Replace']==False)) {
foreach ($Header['Data'] as $HeaderInfo) {
header($HeaderName.': '.$HeaderInfo, False); }}
else { header($HeaderName.': '.$Header['Data'], True); }}
}
}
{
private $prvHTTP_Headers;
private $prvHTTP_Responce;
public function __construct(&$aHTTP_Responce) {
$this->prvHTTP_Headers = array();
$this->prvHTTP_Responce = &$aHTTP_Responce;
}
public function addHeader($aHeader, $aHeaderData, $aReplace = true) {
if ($aReplace) { $this->prvHTTP_Headers[$aHeader] = array('Data' => $aHeaderData); }
else {
if(!isArray($this->prvHTTP_Headers[$aHeader])) {
$this->prvHTTP_Headers[$aHeader] = array();
$this->prvHTTP_Headers[$aHeader]['Replace'] = True;
$ID = count($this->prvHTTP_Headers[$aHeader]['Data']);
$this->prvHTTP_Headers[$aHeader]['Data'][$ID] = $aHeaderData;
}
}
}
public function getData()
{ return $this->prvHTTP_Responce;
}
public function Send()
{
$this->SendHeaders();
echo $this->prvHTTP_Responce; // Beetje buggy !
return True;
}
private function SendHeaders()
{
foreach ($this->prvHTTP_Headers as $HeaderName => $Header) {
if( (array_key_exists('Replace', $Header)) & ($Header['Replace']==False)) {
foreach ($Header['Data'] as $HeaderInfo) {
header($HeaderName.': '.$HeaderInfo, False); }}
else { header($HeaderName.': '.$Header['Data'], True); }}
}
}
Het HTTP 1.0 gedeelte (Caching, redirect, etc)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
include('HTTP_Responce.php');
define('conResponce_NO_CASHING',0);
define('conResponce_PRIVATE',1);
define('conResponce_PUBLIC',2);
class cHTTP_1_0_Responce extends cHTTP_Responce
{
public function setCacheControl ($aLast_Modified, $aExpires, $aPragma) {
$this->setLastModified($aLast_Modified);
$this->setExpires($aExpires);
$this->SetPragma($aPragma);
}
public function redirect($aURL) {
$this->addHeader('Location', $aURL, True);
}
private function setLastModified ($aTimestamp) {
$this->addHeader('Last-Modified', gmdate('r',$aTimestamp), True);
}
private function setExpires ($aTimestamp) {
$this->addHeader('Expires', gmdate('r',$aTimestamp), True);
}
private function setPragma ($aPragma) {
switch ($aPragma) {
case conResponce_NO_CASHING: $this->addHeader('Pragma', 'no-cache', True); break;
case conResponce_PRIVATE: $this->addHeader('Pragma', 'private', True); break;
case conResponce_PUBLIC: $this->addHeader('Pragma', 'public', True); break; }
}
}
define('conResponce_NO_CASHING',0);
define('conResponce_PRIVATE',1);
define('conResponce_PUBLIC',2);
class cHTTP_1_0_Responce extends cHTTP_Responce
{
public function setCacheControl ($aLast_Modified, $aExpires, $aPragma) {
$this->setLastModified($aLast_Modified);
$this->setExpires($aExpires);
$this->SetPragma($aPragma);
}
public function redirect($aURL) {
$this->addHeader('Location', $aURL, True);
}
private function setLastModified ($aTimestamp) {
$this->addHeader('Last-Modified', gmdate('r',$aTimestamp), True);
}
private function setExpires ($aTimestamp) {
$this->addHeader('Expires', gmdate('r',$aTimestamp), True);
}
private function setPragma ($aPragma) {
switch ($aPragma) {
case conResponce_NO_CASHING: $this->addHeader('Pragma', 'no-cache', True); break;
case conResponce_PRIVATE: $this->addHeader('Pragma', 'private', True); break;
case conResponce_PUBLIC: $this->addHeader('Pragma', 'public', True); break; }
}
}
Het HTTP 1.1 gedeelte (Betere Caching control)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Uses:
include('HTTP_1_0_Responce.php');
define('conCacheControl_NO_CASHING',0);
define('conCacheControl_PRIVATE',1);
define('conCacheControl_PUBLIC',2);
define('conCacheControl_MUST_REVALIDATE',3);
define('conCacheControl_PROXY_REVALIDATE',4);
define('conCacheControl_MAX_AGE',5);
define('conCacheControl_SMAX_AGE',6);
// Implementatie:
class cHTTP_1_1_Responce extends cHTTP_1_0_Responce {
public function setCacheControl ($aControl=conCacheControl_NO_CASHING, $aPragma=conCacheControl_NO_CASHING, $aLast_Modified=1, $aExpires=1, $aMaxAge=0) {
$this->setControl($aControl);
cHTTP_1_0_Responce::setCacheControl($aLast_Modified,$aExpires,$aPragma);
}
private function setControl($aControl) {
$Header = 'Cache-Control';
switch ($aControl) {
case conCacheControl_NO_CASHING: $this->addHeader($Header,'no-cache', True); break;
case conCacheControl_PRIVATE: $this->addHeader($Header,'private', True); break;
case conCacheControl_PUBLIC: $this->addHeader($Header,'public', True); break;
case conCacheControl_MUST_REVALIDATE: $this->addHeader($Header,'must-revalidate', True); break;
case conCacheControl_PROXY_REVALIDATE: $this->addHeader($Header,'proxy-revalidate', True); break;
case conCacheControl_MAX_AGE: $this->addHeader($Header,'max-age='.$aMaxAge, True); break;
case conCacheControl_SMAX_AGE: $this->addHeader($Header,'s-maxage='.$aMaxAge, True); break;
}
}
}
include('HTTP_1_0_Responce.php');
define('conCacheControl_NO_CASHING',0);
define('conCacheControl_PRIVATE',1);
define('conCacheControl_PUBLIC',2);
define('conCacheControl_MUST_REVALIDATE',3);
define('conCacheControl_PROXY_REVALIDATE',4);
define('conCacheControl_MAX_AGE',5);
define('conCacheControl_SMAX_AGE',6);
// Implementatie:
class cHTTP_1_1_Responce extends cHTTP_1_0_Responce {
public function setCacheControl ($aControl=conCacheControl_NO_CASHING, $aPragma=conCacheControl_NO_CASHING, $aLast_Modified=1, $aExpires=1, $aMaxAge=0) {
$this->setControl($aControl);
cHTTP_1_0_Responce::setCacheControl($aLast_Modified,$aExpires,$aPragma);
}
private function setControl($aControl) {
$Header = 'Cache-Control';
switch ($aControl) {
case conCacheControl_NO_CASHING: $this->addHeader($Header,'no-cache', True); break;
case conCacheControl_PRIVATE: $this->addHeader($Header,'private', True); break;
case conCacheControl_PUBLIC: $this->addHeader($Header,'public', True); break;
case conCacheControl_MUST_REVALIDATE: $this->addHeader($Header,'must-revalidate', True); break;
case conCacheControl_PROXY_REVALIDATE: $this->addHeader($Header,'proxy-revalidate', True); break;
case conCacheControl_MAX_AGE: $this->addHeader($Header,'max-age='.$aMaxAge, True); break;
case conCacheControl_SMAX_AGE: $this->addHeader($Header,'s-maxage='.$aMaxAge, True); break;
}
}
}
Is hier een "STANDAARD" voor, of ben ik weer de eerste die HTTP gaat gebruiken in combinatie met PHP en een windows PC?
Groetjes: Lucifer
Er zijn nog geen reacties op dit bericht.