Changeset 11846
- Timestamp:
- 08/30/07 11:02:09 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.core/midcom/services/cache/module/content.php
r11359 r11846 346 346 function _check_hit() 347 347 { 348 debug_push_class(__CLASS__, __FUNCTION__);349 350 348 foreach ($GLOBALS["argv"] as $arg) 351 349 { … … 364 362 if (count($_POST) > 0) 365 363 { 366 debug_add("POST variables have been found, setting no_cache and not checking for a hit."); 364 debug_push_class(__CLASS__, __FUNCTION__); 365 debug_add('POST variables have been found, setting no_cache and not checking for a hit.'); 367 366 $this->no_cache(); 368 367 debug_pop(); … … 373 372 if ($this->_uncached) 374 373 { 375 debug_add("We are in uncached operation, skipping check_hit detection."); 374 debug_push_class(__CLASS__, __FUNCTION__); 375 debug_add('We are in uncached operation, skipping check_hit detection.'); 376 376 debug_pop(); 377 377 return; … … 381 381 if ($this->_multilang) 382 382 { 383 $i18n = new midcom_services_i18n( "en");383 $i18n = new midcom_services_i18n('en'); 384 384 $entry_name = 'LANG=' . $i18n->get_current_language() . ";" ; 385 385 } … … 388 388 $entry_name = 'LANG=ALL;'; 389 389 } 390 $midgard = mgd_get_midgard(); 391 $entry_name .= "USER={$ midgard->user};";392 $entry_name .= "URL=" . $_SERVER[ "REQUEST_URI"];390 391 $entry_name .= "USER={$_MIDGARD['user']};"; 392 $entry_name .= "URL=" . $_SERVER['REQUEST_URI']; 393 393 394 394 $this->_meta_cache->open(); … … 398 398 $data = $this->_meta_cache->get($entry_name); 399 399 400 if (!is_null($data[ "expires"]))401 { 402 if ($data[ "expires"] < time())400 if (!is_null($data['expires'])) 401 { 402 if ($data['expires'] < time()) 403 403 { 404 debug_push_class(__CLASS__, __FUNCTION__); 404 405 debug_add("Current page is in cache, but has expired.", MIDCOM_LOG_INFO); 405 406 debug_pop(); … … 408 409 } 409 410 410 debug_add("Cache hit for URI " . $entry_name, MIDCOM_LOG_INFO);411 412 411 // Check If-Modified-Since and If-None-Match, do content output only if 413 412 // we have a not modified match. … … 418 417 { 419 418 $this->_data_cache->close(); 420 debug_add("Current page is in not in the data cache, (possible ghost read)."); 419 debug_push_class(__CLASS__, __FUNCTION__); 420 debug_add("Current page is in not in the data cache, (possible ghost read).", MIDCOM_LOG_WARN); 421 421 debug_pop(); 422 422 return; … … 426 426 $this->_meta_cache->close(); 427 427 428 foreach ($data[ "sent_headers"] as $header)428 foreach ($data['sent_headers'] as $header) 429 429 { 430 430 header($header); … … 439 439 } 440 440 441 debug_add("Exiting", MIDCOM_LOG_INFO);442 441 exit(); 443 442 } 444 443 445 444 $this->_meta_cache->close(); 446 447 debug_add("Cache miss for URI {$entry_name}", MIDCOM_LOG_INFO);448 debug_pop();449 445 } 450 446 … … 455 451 function _start_caching() 456 452 { 457 debug_push_class(__CLASS__, __FUNCTION__);458 debug_add('Starting output buffering with disabled implicit flush...');459 453 ob_implicit_flush(false); 460 454 ob_start(); 461 455 $this->_obrunning = true; 462 debug_pop();463 456 } 464 457 … … 485 478 } 486 479 487 debug_push_class(__CLASS__, __FUNCTION__);488 489 480 $this->_no_cache = true; 490 481 … … 492 483 { 493 484 // Whatever is wrong here, we return. 485 debug_push_class(__CLASS__, __FUNCTION__); 494 486 debug_add('Warning, we should move to no_cache but headers have already been sent, skipping header transmission.', MIDCOM_LOG_ERROR); 495 487 debug_pop(); … … 497 489 } 498 490 499 debug_add('Caching disabled by no_cache() method, sending appropriate headers.', MIDCOM_LOG_INFO);500 491 header('Cache-Control: no-store, no-cache, must-revalidate'); 501 492 header('Cache-Control: post-check=0, pre-check=0', false); … … 510 501 } 511 502 // PONDER:, send expires header (set to long time in past) as well ?? 512 debug_pop();513 503 } 514 504 … … 538 528 return; 539 529 } 540 debug_push_class(__CLASS__, __FUNCTION__);541 debug_add("Caching disabled by uncached() method.", MIDCOM_LOG_INFO);542 debug_pop();543 530 $this->_uncached = true; 544 531 } … … 571 558 || $this->_expires > $timestamp) 572 559 { 573 debug_push_class(__CLASS__, __FUNCTION__);574 debug_add("Setting expired to {$timestamp}.", MIDCOM_LOG_INFO);575 560 $this->_expires = $timestamp; 576 debug_pop();577 561 } 578 562 } … … 591 575 function content_type($type) 592 576 { 593 debug_push_class(__CLASS__, __FUNCTION__);594 debug_add("Setting Content-Type to {$type}.", MIDCOM_LOG_INFO);595 577 $this->_content_type = $type; 596 578 … … 599 581 $header = "Content-type: " . $this->_content_type; 600 582 header($header); 601 debug_pop();602 583 } 603 584 … … 614 595 function enable_live_mode() 615 596 { 616 debug_push_class(__CLASS__, __FUNCTION__);617 618 597 if ($this->_live_mode) 619 598 { 599 debug_push_class(__CLASS__, __FUNCTION__); 620 600 debug_add('Cannot enter live mode twice, ignoring request.', MIDCOM_LOG_WARN); 621 601 debug_pop(); 622 602 return; 623 603 } 624 625 debug_add('Disabling output cache, entering live-mode.', MIDCOM_LOG_INFO);626 604 627 605 $this->_live_mode = true; … … 648 626 $this->_obrunning = false; 649 627 } 650 651 debug_pop();652 628 } 653 629 … … 662 638 function register_sent_header($header) 663 639 { 664 debug_push_class(__CLASS__, __FUNCTION__);665 debug_add("Registering sent header '{$header}'");666 640 $this->_sent_headers[] = $header; 667 debug_pop();668 641 } 669 642 … … 697 670 function _check_not_modified($last_modified, $etag) 698 671 { 699 debug_push_class(__CLASS__, __FUNCTION__);700 672 if (headers_sent()) 701 673 { 674 debug_push_class(__CLASS__, __FUNCTION__); 702 675 debug_add("The headers have already been sent, cannot do a not modified check.", MIDCOM_LOG_INFO); 703 676 debug_pop(); 704 677 return false; 705 678 } 706 707 debug_print_r('Checking this $_SERVER for 304 if-modified headers:', $_SERVER);708 debug_add("Checking HTTP headers against last modified date {$last_modified} (" . gmdate("D, d M Y H:i:s", $last_modified) . " GMT) and E-Tag {$etag}");709 679 710 680 // These variables are set to true if the corresponding header indicates a 403 is … … 717 687 { 718 688 // The E-Tag is different, so we cannot 304 here. 689 debug_push_class(__CLASS__, __FUNCTION__); 719 690 debug_add("The HTTP supplied E-Tag requirement does not match: {$_SERVER['HTTP_IF_NONE_MATCH']} (!= {$etag})"); 720 691 debug_pop(); 721 692 return false; 722 693 } 723 debug_add("If-none-match against {$_SERVER['HTTP_IF_NONE_MATCH']}.");724 694 $if_none_match = true; 725 695 } … … 735 705 { 736 706 // Last Modified does not match, so we cannot 304 here. 707 debug_push_class(__CLASS__, __FUNCTION__); 737 708 debug_add("The supplied HTTP Last Modified requirement does not match: {$_SERVER['HTTP_IF_MODIFIED_SINCE']}."); 738 709 debug_add("If-Modified-Since: ({$modified_since}) " . gmdate("D, d M Y H:i:s", $modified_since) . ' GMT'); … … 741 712 return false; 742 713 } 743 debug_add("If-modified-since match against {$_SERVER['HTTP_IF_MODIFIED_SINCE']}, parsed time was {$modified_since}.");744 714 $if_modified_since = true; 745 715 } … … 747 717 if (! $if_modified_since && ! $if_none_match) 748 718 { 719 debug_push_class(__CLASS__, __FUNCTION__); 749 720 debug_add('No If-Header was detected, we cannot 304 therefore.'); 750 721 debug_pop(); 751 722 return false; 752 723 } 753 754 debug_add("We have a 304 match, sending the appropriate header and exitting afterwards.");755 724 756 725 if ($this->_obrunning) … … 780 749 function _finish_caching() 781 750 { 782 debug_push_class(__CLASS__, __FUNCTION__);783 784 751 if ( $this->_no_cache 785 752 || $this->_live_mode) … … 787 754 if ($this->_obrunning) 788 755 { 789 debug_add("We are on no_cache/live mode, flushing output buffer and exitting");790 756 ob_end_flush(); 791 757 } 792 else793 {794 debug_add("We don't had an outputbuffer running though the caching system was active, ignoring this as we are in no_cache/live mode!",795 MIDCOM_LOG_WARN);796 }797 debug_pop();798 758 return; 799 759 } … … 814 774 header($etag_header); 815 775 $this->register_sent_header($etag_header); 816 debug_add("Sent Header: {$etag_header}");817 776 818 777 // Register additional Headers around the current output request … … 824 783 if ($this->_uncached) 825 784 { 826 debug_add("Not writing cache file, we are in uncached operation mode."); 785 debug_push_class(__CLASS__, __FUNCTION__); 786 debug_add('Not writing cache file, we are in uncached operation mode.'); 787 debug_pop(); 827 788 } 828 789 else … … 842 803 $entry_name .= "URL=" . $_SERVER["REQUEST_URI"]; 843 804 844 debug_add("Creating cache entry for $entry_name", MIDCOM_LOG_INFO); 845 846 $entry_data["expires"] = $this->_expires; 847 $entry_data["etag"] = $etag; 848 $entry_data["last_modified"] = $this->_last_modified; 849 $entry_data["sent_headers"] = $this->_sent_headers; 805 debug_push_class(__CLASS__, __FUNCTION__); 806 debug_add("Creating cache entry for {$entry_name}", MIDCOM_LOG_INFO); 807 debug_pop(); 808 809 $entry_data['expires'] = $this->_expires; 810 $entry_data['etag'] = $etag; 811 $entry_data['last_modified'] = $this->_last_modified; 812 $entry_data['sent_headers'] = $this->_sent_headers; 850 813 851 814 $this->_meta_cache->open(true); … … 862 825 $this->_obrunning = false; 863 826 } 864 debug_add("Cache run complete.");865 debug_pop();866 827 } 867 828 … … 880 841 function _complete_sent_headers(& $cache_data) 881 842 { 882 debug_push_class(__CLASS__, __FUNCTION__);883 884 843 // Detected headers flags 885 844 $ranges = false; … … 889 848 foreach ($this->_sent_headers as $header) 890 849 { 891 if (strncasecmp($header, "Accept-Ranges", 13) == 0)850 if (strncasecmp($header, 'Accept-Ranges', 13) == 0) 892 851 { 893 852 $ranges = true; 894 853 } 895 else if (strncasecmp($header, "Content-Length", 14) == 0)854 else if (strncasecmp($header, 'Content-Length', 14) == 0) 896 855 { 897 856 $size = true; 898 857 } 899 else if (strncasecmp($header, "Last-Modified", 13) == 0)858 else if (strncasecmp($header, 'Last-Modified', 13) == 0) 900 859 { 901 860 $lastmod = true; … … 909 868 if ($this->_last_modified == -1) 910 869 { 870 debug_push_class(__CLASS__, __FUNCTION__); 911 871 debug_add("Failed to extract the timecode from the last modified header '{$header}', defaulting to the current time.", MIDCOM_LOG_WARN); 872 debug_pop(); 912 873 $this->_last_modified = time(); 913 874 } … … 920 881 header ($header); 921 882 $this->_sent_headers[] = $header; 922 debug_add("Added Header '$header'");923 883 } 924 884 if (! $size) … … 937 897 header ($header); 938 898 $this->_sent_headers[] = $header; 939 debug_add("Added Header '$header'");940 899 break; 941 900 } … … 947 906 */ 948 907 $time = 0; 949 foreach ($ GLOBALS["midcom"]->_context as $id => $context)908 foreach ($_MIDCOM->_context as $id => $context) 950 909 { 951 910 $meta = $_MIDCOM->get_26_request_metadata($id); 952 debug_add("SCANNING context {$id}, edited time is {$meta['lastmodified']} -- {$context[MIDCOM_CONTEXT_COMPONENT]}");953 911 if ($meta['lastmodified'] > $time) 954 912 { … … 960 918 $time = time(); 961 919 } 920 921 debug_push_class(__CLASS__, __FUNCTION__); 962 922 debug_add("Setting last modified to the timestamp {$time} which is: " . gmdate("D, d M Y H:i:s", $time) . ' GMT'); 923 debug_pop(); 924 963 925 $header = "Last-Modified: " . gmdate("D, d M Y H:i:s", $time) . ' GMT'; 964 926 header ($header); 965 927 $this->_sent_headers[] = $header; 966 928 $this->_last_modified = $time; 967 debug_add("Added Header '$header'");968 929 } 969 930 … … 1014 975 header ($header); 1015 976 $this->_sent_headers[] = $header; 1016 debug_add("Added Header '$header'");1017 977 } 1018 978 if ($pragma !== false) … … 1021 981 header ($header); 1022 982 $this->_sent_headers[] = $header; 1023 debug_add("Added Header '$header'");1024 983 } 1025 984 if ($expires !== false) … … 1028 987 header ($header); 1029 988 $this->_sent_headers[] = $header; 1030 debug_add("Added Header '$header'"); 1031 } 1032 1033 debug_pop(); 989 } 1034 990 } 1035 991
