/usr/share/doc/ruby-passenger-doc/Users guide Apache.html is in ruby-passenger-doc 4.0.37-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 13946 13947 13948 13949 13950 13951 13952 13953 13954 13955 13956 13957 13958 13959 13960 13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 13978 13979 13980 13981 13982 13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 14537 14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593 14594 14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 14611 14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634 14635 14636 14637 14638 14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 14755 14756 14757 14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 14793 14794 14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 14849 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 14860 14861 14862 14863 14864 14865 14866 14867 14868 14869 14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882 14883 14884 14885 14886 14887 14888 14889 14890 14891 14892 14893 14894 14895 14896 14897 14898 14899 14900 14901 14902 14903 14904 14905 14906 14907 14908 14909 14910 14911 14912 14913 14914 14915 14916 14917 14918 14919 14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 14931 14932 14933 14934 14935 14936 14937 14938 14939 14940 14941 14942 14943 14944 14945 14946 14947 14948 14949 14950 14951 14952 14953 14954 14955 14956 14957 14958 14959 14960 14961 14962 14963 14964 14965 14966 14967 14968 14969 14970 14971 14972 14973 14974 14975 14976 14977 14978 14979 14980 14981 14982 14983 14984 14985 14986 14987 14988 14989 14990 14991 14992 14993 14994 14995 14996 14997 14998 14999 15000 15001 15002 15003 15004 15005 15006 15007 15008 15009 15010 15011 15012 15013 15014 15015 15016 15017 15018 15019 15020 15021 15022 15023 15024 15025 15026 15027 15028 15029 15030 15031 15032 15033 15034 15035 15036 15037 15038 15039 15040 15041 15042 15043 15044 15045 15046 15047 15048 15049 15050 15051 15052 15053 15054 15055 15056 15057 15058 15059 15060 15061 15062 15063 15064 15065 15066 15067 15068 15069 15070 15071 15072 15073 15074 15075 15076 15077 15078 15079 15080 15081 15082 15083 15084 15085 15086 15087 15088 15089 15090 15091 15092 15093 15094 15095 15096 15097 15098 15099 15100 15101 15102 15103 15104 15105 15106 15107 15108 15109 15110 15111 15112 15113 15114 15115 15116 15117 15118 15119 15120 15121 15122 15123 15124 15125 15126 15127 15128 15129 15130 15131 15132 15133 15134 15135 15136 15137 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 15154 15155 15156 15157 15158 15159 15160 15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 15175 15176 15177 15178 15179 15180 15181 15182 15183 15184 15185 15186 15187 15188 15189 15190 15191 15192 15193 15194 15195 15196 15197 15198 15199 15200 15201 15202 15203 15204 15205 15206 15207 15208 15209 15210 15211 15212 15213 15214 15215 15216 15217 15218 15219 15220 15221 15222 15223 15224 15225 15226 15227 15228 15229 15230 15231 15232 15233 15234 15235 15236 15237 15238 15239 15240 15241 15242 15243 15244 15245 15246 15247 15248 15249 15250 15251 15252 15253 15254 15255 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265 15266 15267 15268 15269 15270 15271 15272 15273 15274 15275 15276 15277 15278 15279 15280 15281 15282 15283 15284 15285 15286 15287 15288 15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 15304 15305 15306 15307 15308 15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 15321 15322 15323 15324 15325 15326 15327 15328 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 15339 15340 15341 15342 15343 15344 15345 15346 15347 15348 15349 15350 15351 15352 15353 15354 15355 15356 15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 15373 15374 15375 15376 15377 15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408 15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 15437 15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 15589 15590 15591 15592 15593 15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 15705 15706 15707 15708 15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 15722 15723 15724 15725 15726 15727 15728 15729 15730 15731 15732 15733 15734 15735 15736 15737 15738 15739 15740 15741 15742 15743 15744 15745 15746 15747 15748 15749 15750 15751 15752 15753 15754 15755 15756 15757 15758 15759 15760 15761 15762 15763 15764 15765 15766 15767 15768 15769 15770 15771 15772 15773 15774 15775 15776 15777 15778 15779 15780 15781 15782 15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 15794 15795 15796 15797 15798 15799 15800 15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821 15822 15823 15824 15825 15826 15827 15828 15829 15830 15831 15832 15833 15834 15835 15836 15837 15838 15839 15840 15841 15842 15843 15844 15845 15846 15847 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 15876 15877 15878 15879 15880 15881 15882 15883 15884 15885 15886 15887 15888 15889 15890 15891 15892 15893 15894 15895 15896 15897 15898 15899 15900 15901 15902 15903 15904 15905 15906 15907 15908 15909 15910 15911 15912 15913 15914 15915 15916 15917 15918 15919 15920 15921 15922 15923 15924 15925 15926 15927 15928 15929 15930 15931 15932 15933 15934 15935 15936 15937 15938 15939 15940 15941 15942 15943 15944 15945 15946 15947 15948 15949 15950 15951 15952 15953 15954 15955 15956 15957 15958 15959 15960 15961 15962 15963 15964 15965 15966 15967 15968 15969 15970 15971 15972 15973 15974 15975 15976 15977 15978 15979 15980 15981 15982 15983 15984 15985 15986 15987 15988 15989 15990 15991 15992 15993 15994 15995 15996 15997 15998 15999 16000 16001 16002 16003 16004 16005 16006 16007 16008 16009 16010 16011 16012 16013 16014 16015 16016 16017 16018 16019 16020 16021 16022 16023 16024 16025 16026 16027 16028 16029 16030 16031 16032 16033 16034 16035 16036 16037 16038 16039 16040 16041 16042 16043 16044 16045 16046 16047 16048 16049 16050 16051 16052 16053 16054 16055 16056 16057 16058 16059 16060 16061 16062 16063 16064 16065 16066 16067 16068 16069 16070 16071 16072 16073 16074 16075 16076 16077 16078 16079 16080 16081 16082 16083 16084 16085 16086 16087 16088 16089 16090 16091 16092 16093 16094 16095 16096 16097 16098 16099 16100 16101 16102 16103 16104 16105 16106 16107 16108 16109 16110 16111 16112 16113 16114 16115 16116 16117 16118 16119 16120 16121 16122 16123 16124 16125 16126 16127 16128 16129 16130 16131 16132 16133 16134 16135 16136 16137 16138 16139 16140 16141 16142 16143 16144 16145 16146 16147 16148 16149 16150 16151 16152 16153 16154 16155 16156 16157 16158 16159 16160 16161 16162 16163 16164 16165 16166 16167 16168 16169 16170 16171 16172 16173 16174 16175 16176 16177 16178 16179 16180 16181 16182 16183 16184 16185 16186 16187 16188 16189 16190 16191 16192 16193 16194 16195 16196 16197 16198 16199 16200 16201 16202 16203 16204 16205 16206 16207 16208 16209 16210 16211 16212 16213 16214 16215 16216 16217 16218 16219 16220 16221 16222 16223 16224 16225 16226 16227 16228 16229 16230 16231 16232 16233 16234 16235 16236 16237 16238 16239 16240 16241 16242 16243 16244 16245 16246 16247 16248 16249 16250 16251 16252 16253 16254 16255 16256 16257 16258 16259 16260 16261 16262 16263 16264 16265 16266 16267 16268 16269 16270 16271 16272 16273 16274 16275 16276 16277 16278 16279 16280 16281 16282 16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 16297 16298 16299 16300 16301 16302 16303 16304 16305 16306 16307 16308 16309 16310 16311 16312 16313 16314 16315 16316 16317 16318 16319 16320 16321 16322 16323 16324 16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 16336 16337 16338 16339 16340 16341 16342 16343 16344 16345 16346 16347 16348 16349 16350 16351 16352 16353 16354 16355 16356 16357 16358 16359 16360 16361 16362 16363 16364 16365 16366 16367 16368 16369 16370 16371 16372 16373 16374 16375 16376 16377 16378 16379 16380 16381 16382 16383 16384 16385 16386 16387 16388 16389 16390 16391 16392 16393 16394 16395 16396 16397 16398 16399 16400 16401 16402 16403 16404 16405 16406 16407 16408 16409 16410 16411 16412 16413 16414 16415 16416 16417 16418 16419 16420 16421 16422 16423 16424 16425 16426 16427 16428 16429 16430 16431 16432 16433 16434 16435 16436 16437 16438 16439 16440 16441 16442 16443 16444 16445 16446 16447 16448 16449 16450 16451 16452 16453 16454 16455 16456 16457 16458 16459 16460 16461 16462 16463 16464 16465 16466 16467 16468 16469 16470 16471 16472 16473 16474 16475 16476 16477 16478 16479 16480 16481 16482 16483 16484 16485 16486 16487 16488 16489 16490 16491 16492 16493 16494 16495 16496 16497 16498 16499 16500 16501 16502 16503 16504 16505 16506 16507 16508 16509 16510 16511 16512 16513 16514 16515 16516 16517 16518 16519 16520 16521 16522 16523 16524 16525 16526 16527 16528 16529 16530 16531 16532 16533 16534 16535 16536 16537 16538 16539 16540 16541 16542 16543 16544 16545 16546 16547 16548 16549 16550 16551 16552 16553 16554 16555 16556 16557 16558 16559 16560 16561 16562 16563 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574 16575 16576 16577 16578 16579 16580 16581 16582 16583 16584 16585 16586 16587 16588 16589 16590 16591 16592 16593 16594 16595 16596 16597 16598 16599 16600 16601 16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 16644 16645 16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 16668 16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 16719 16720 16721 16722 16723 16724 16725 16726 16727 16728 16729 16730 16731 16732 16733 16734 16735 16736 16737 16738 16739 16740 16741 16742 16743 16744 16745 16746 16747 16748 16749 16750 16751 16752 16753 16754 16755 16756 16757 16758 16759 16760 16761 16762 16763 16764 16765 16766 16767 16768 16769 16770 16771 16772 16773 16774 16775 16776 16777 16778 16779 16780 16781 16782 16783 16784 16785 16786 16787 16788 16789 16790 16791 16792 16793 16794 16795 16796 16797 16798 16799 16800 16801 16802 16803 16804 16805 16806 16807 16808 16809 16810 16811 16812 16813 16814 16815 16816 16817 16818 16819 16820 16821 16822 16823 16824 16825 16826 16827 16828 16829 16830 16831 16832 16833 16834 16835 16836 16837 16838 16839 16840 16841 16842 16843 16844 16845 16846 16847 16848 16849 16850 16851 16852 16853 16854 16855 16856 16857 16858 16859 16860 16861 16862 16863 16864 16865 16866 16867 16868 16869 16870 16871 16872 16873 16874 16875 16876 16877 16878 16879 16880 16881 16882 16883 16884 16885 16886 16887 16888 16889 16890 16891 16892 16893 16894 16895 16896 16897 16898 16899 16900 16901 16902 16903 16904 16905 16906 16907 16908 16909 16910 16911 16912 16913 16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943 16944 16945 16946 16947 16948 16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 16961 16962 16963 16964 16965 16966 16967 16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 16992 16993 16994 16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 17014 17015 17016 17017 17018 17019 17020 17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089 17090 17091 17092 17093 17094 17095 17096 17097 17098 17099 17100 17101 17102 17103 17104 17105 17106 17107 17108 17109 17110 17111 17112 17113 17114 17115 17116 17117 17118 17119 17120 17121 17122 17123 17124 17125 17126 17127 17128 17129 17130 17131 17132 17133 17134 17135 17136 17137 17138 17139 17140 17141 17142 17143 17144 17145 17146 17147 17148 17149 17150 17151 17152 17153 17154 17155 17156 17157 17158 17159 17160 17161 17162 17163 17164 17165 17166 17167 17168 17169 17170 17171 17172 17173 17174 17175 17176 17177 17178 17179 17180 17181 17182 17183 17184 17185 17186 17187 17188 17189 17190 17191 17192 17193 17194 17195 17196 17197 17198 17199 17200 17201 17202 17203 17204 17205 17206 17207 17208 17209 17210 17211 17212 17213 17214 17215 17216 17217 17218 17219 17220 17221 17222 17223 17224 17225 17226 17227 17228 17229 17230 17231 17232 17233 17234 17235 17236 17237 17238 17239 17240 17241 17242 17243 17244 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 17255 17256 17257 17258 17259 17260 17261 17262 17263 17264 17265 17266 17267 17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 17286 17287 17288 17289 17290 17291 17292 17293 17294 17295 17296 17297 17298 17299 17300 17301 17302 17303 17304 17305 17306 17307 17308 17309 17310 17311 17312 17313 17314 17315 17316 17317 17318 17319 17320 17321 17322 17323 17324 17325 17326 17327 17328 17329 17330 17331 17332 17333 17334 17335 17336 17337 17338 17339 17340 17341 17342 17343 17344 17345 17346 17347 17348 17349 17350 17351 17352 17353 17354 17355 17356 17357 17358 17359 17360 17361 17362 17363 17364 17365 17366 17367 17368 17369 17370 17371 17372 17373 17374 17375 17376 17377 17378 17379 17380 17381 17382 17383 17384 17385 17386 17387 17388 17389 17390 17391 17392 17393 17394 17395 17396 17397 17398 17399 17400 17401 17402 17403 17404 17405 17406 17407 17408 17409 17410 17411 17412 17413 17414 17415 17416 17417 17418 17419 17420 17421 17422 17423 17424 17425 17426 17427 17428 17429 17430 17431 17432 17433 17434 17435 17436 17437 17438 17439 17440 17441 17442 17443 17444 17445 17446 17447 17448 17449 17450 17451 17452 17453 17454 17455 17456 17457 17458 17459 17460 17461 17462 17463 17464 17465 17466 17467 17468 17469 17470 17471 17472 17473 17474 17475 17476 17477 17478 17479 17480 17481 17482 17483 17484 17485 17486 17487 17488 17489 17490 17491 17492 17493 17494 17495 17496 17497 17498 17499 17500 17501 17502 17503 17504 17505 17506 17507 17508 17509 17510 17511 17512 17513 17514 17515 17516 17517 17518 17519 17520 17521 17522 17523 17524 17525 17526 17527 17528 17529 17530 17531 17532 17533 17534 17535 17536 17537 17538 17539 17540 17541 17542 17543 17544 17545 17546 17547 17548 17549 17550 17551 17552 17553 17554 17555 17556 17557 17558 17559 17560 17561 17562 17563 17564 17565 17566 17567 17568 17569 17570 17571 17572 17573 17574 17575 17576 17577 17578 17579 17580 17581 17582 17583 17584 17585 17586 17587 17588 17589 17590 17591 17592 17593 17594 17595 17596 17597 17598 17599 17600 17601 17602 17603 17604 17605 17606 17607 17608 17609 17610 17611 17612 17613 17614 17615 17616 17617 17618 17619 17620 17621 17622 17623 17624 17625 17626 17627 17628 17629 17630 17631 17632 17633 17634 17635 17636 17637 17638 17639 17640 17641 17642 17643 17644 17645 17646 17647 17648 17649 17650 17651 17652 17653 17654 17655 17656 17657 17658 17659 17660 17661 17662 17663 17664 17665 17666 17667 17668 17669 17670 17671 17672 17673 17674 17675 17676 17677 17678 17679 17680 17681 17682 17683 17684 17685 17686 17687 17688 17689 17690 17691 17692 17693 17694 17695 17696 17697 17698 17699 17700 17701 17702 17703 17704 17705 17706 17707 17708 17709 17710 17711 17712 17713 17714 17715 17716 17717 17718 17719 17720 17721 17722 17723 17724 17725 17726 17727 17728 17729 17730 17731 17732 17733 17734 17735 17736 17737 17738 17739 17740 17741 17742 17743 17744 17745 17746 17747 17748 17749 17750 17751 17752 17753 17754 17755 17756 17757 17758 17759 17760 17761 17762 17763 17764 17765 17766 17767 17768 17769 17770 17771 17772 17773 17774 17775 17776 17777 17778 17779 17780 17781 17782 17783 17784 17785 17786 17787 17788 17789 17790 17791 17792 17793 17794 17795 17796 17797 17798 17799 17800 17801 17802 17803 17804 17805 17806 17807 17808 17809 17810 17811 17812 17813 17814 17815 17816 17817 17818 17819 17820 17821 17822 17823 17824 17825 17826 17827 17828 17829 17830 17831 17832 17833 17834 17835 17836 17837 17838 17839 17840 17841 17842 17843 17844 17845 17846 17847 17848 17849 17850 17851 17852 17853 17854 17855 17856 17857 17858 17859 17860 17861 17862 17863 17864 17865 17866 17867 17868 17869 17870 17871 17872 17873 17874 17875 17876 17877 17878 17879 17880 17881 17882 17883 17884 17885 17886 17887 17888 17889 17890 17891 17892 17893 17894 17895 17896 17897 17898 17899 17900 17901 17902 17903 17904 17905 17906 17907 17908 17909 17910 17911 17912 17913 17914 17915 17916 17917 17918 17919 17920 17921 17922 17923 17924 17925 17926 17927 17928 17929 17930 17931 17932 17933 17934 17935 17936 17937 17938 17939 17940 17941 17942 17943 17944 17945 17946 17947 17948 17949 17950 17951 17952 17953 17954 17955 17956 17957 17958 17959 17960 17961 17962 17963 17964 17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006 18007 18008 18009 18010 18011 18012 18013 18014 18015 18016 18017 18018 18019 18020 18021 18022 18023 18024 18025 18026 18027 18028 18029 18030 18031 18032 18033 18034 18035 18036 18037 18038 18039 18040 18041 18042 | <!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.9">
<title>Phusion Passenger users guide, Apache version</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
/* Default font. */
body {
font-family: Georgia,serif;
}
/* Title font. */
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
font-family: Arial,Helvetica,sans-serif;
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
h5 {
font-size: 1.0em;
}
div.sectionbody {
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
ul > li { color: #aaa; }
ul > li > * { color: black; }
pre {
padding: 0;
margin: 0;
}
#author {
color: #527bbd;
font-weight: bold;
font-size: 1.1em;
}
#email {
}
#revnumber, #revdate, #revremark {
}
#footer {
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
#footer-text {
float: left;
padding-bottom: 0.5em;
}
#footer-badges {
float: right;
padding-bottom: 0.5em;
}
#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid #dddddd;
border-left: 4px solid #f0f0f0;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid #dddddd;
border-left: 5px solid #f0f0f0;
background: #f8f8f8;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #f0f0f0;
color: #777777;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > pre.content {
font-family: inherit;
font-size: inherit;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
div.colist td {
padding-right: 0.5em;
padding-bottom: 0.3em;
vertical-align: top;
}
div.colist td img {
margin-top: 0.3em;
}
@media print {
#footer-badges { display: none; }
}
#toc {
margin-bottom: 2.5em;
}
#toctitle {
color: #527bbd;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
span.aqua { color: aqua; }
span.black { color: black; }
span.blue { color: blue; }
span.fuchsia { color: fuchsia; }
span.gray { color: gray; }
span.green { color: green; }
span.lime { color: lime; }
span.maroon { color: maroon; }
span.navy { color: navy; }
span.olive { color: olive; }
span.purple { color: purple; }
span.red { color: red; }
span.silver { color: silver; }
span.teal { color: teal; }
span.white { color: white; }
span.yellow { color: yellow; }
span.aqua-background { background: aqua; }
span.black-background { background: black; }
span.blue-background { background: blue; }
span.fuchsia-background { background: fuchsia; }
span.gray-background { background: gray; }
span.green-background { background: green; }
span.lime-background { background: lime; }
span.maroon-background { background: maroon; }
span.navy-background { background: navy; }
span.olive-background { background: olive; }
span.purple-background { background: purple; }
span.red-background { background: red; }
span.silver-background { background: silver; }
span.teal-background { background: teal; }
span.white-background { background: white; }
span.yellow-background { background: yellow; }
span.big { font-size: 2em; }
span.small { font-size: 0.6em; }
span.underline { text-decoration: underline; }
span.overline { text-decoration: overline; }
span.line-through { text-decoration: line-through; }
/*
* xhtml11 specific
*
* */
tt {
font-family: monospace;
font-size: inherit;
color: navy;
}
div.tableblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-weight: bold;
color: #527bbd;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
/*
* html5 specific
*
* */
.monospaced {
font-family: monospace;
font-size: inherit;
color: navy;
}
table.tableblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
thead, p.tableblock.header {
font-weight: bold;
color: #527bbd;
}
p.tableblock {
margin-top: 0;
}
table.tableblock {
border-width: 3px;
border-spacing: 0px;
border-style: solid;
border-color: #527bbd;
border-collapse: collapse;
}
th.tableblock, td.tableblock {
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #527bbd;
}
table.tableblock.frame-topbot {
border-left-style: hidden;
border-right-style: hidden;
}
table.tableblock.frame-sides {
border-top-style: hidden;
border-bottom-style: hidden;
}
table.tableblock.frame-none {
border-style: hidden;
}
th.tableblock.halign-left, td.tableblock.halign-left {
text-align: left;
}
th.tableblock.halign-center, td.tableblock.halign-center {
text-align: center;
}
th.tableblock.halign-right, td.tableblock.halign-right {
text-align: right;
}
th.tableblock.valign-top, td.tableblock.valign-top {
vertical-align: top;
}
th.tableblock.valign-middle, td.tableblock.valign-middle {
vertical-align: middle;
}
th.tableblock.valign-bottom, td.tableblock.valign-bottom {
vertical-align: bottom;
}
/*
* manpage specific
*
* */
body.manpage h1 {
padding-top: 0.5em;
padding-bottom: 0.5em;
border-top: 2px solid silver;
border-bottom: 2px solid silver;
}
body.manpage h2 {
border-style: none;
}
body.manpage div.sectionbody {
margin-left: 3em;
}
@media print {
body.manpage div#toc { display: none; }
}
/*
* Theme specific overrides of the preceding (asciidoc.css) CSS.
*
*/
body {
font-family: Garamond, Georgia, serif;
font-size: 17px;
color: #3E4349;
line-height: 1.3em;
}
h1, h2, h3, h4, h5, h6,
div.title, caption.title,
thead, p.table.header,
#toctitle,
#author, #revnumber, #revdate, #revremark,
#footer {
font-family: Garmond, Georgia, serif;
font-weight: normal;
border-bottom-width: 0;
color: #3E4349;
}
div.title, caption.title { color: #596673; font-weight: bold; }
h1 { font-size: 240%; }
h2 { font-size: 180%; }
h3 { font-size: 150%; }
h4 { font-size: 130%; }
h5 { font-size: 115%; }
h6 { font-size: 100%; }
#header h1 { margin-top: 0; }
#toc {
color: #444444;
line-height: 1.5;
padding-top: 1.5em;
}
#toctitle {
font-size: 20px;
}
#toc a {
border-bottom: 1px dotted #999999;
color: #444444 !important;
text-decoration: none !important;
}
#toc a:hover {
border-bottom: 1px solid #6D4100;
color: #6D4100 !important;
text-decoration: none !important;
}
div.toclevel1 { margin-top: 0.2em; font-size: 16px; }
div.toclevel2 { margin-top: 0.15em; font-size: 14px; }
em, dt, td.hdlist1 { color: black; }
strong { color: #3E4349; }
a { color: #004B6B; text-decoration: none; border-bottom: 1px dotted #004B6B; }
a:visited { color: #615FA0; border-bottom: 1px dotted #615FA0; }
a:hover { color: #6D4100; border-bottom: 1px solid #6D4100; }
div.tableblock > table, table.tableblock { border: 3px solid #E8E8E8; }
th.tableblock, td.tableblock { border: 1px solid #E8E8E8; }
ul > li > * { color: #3E4349; }
pre, tt, .monospaced { font-family: Consolas,Menlo,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace; }
tt, .monospaced { font-size: 0.9em; color: black;
}
div.exampleblock > div.content, div.sidebarblock > div.content, div.listingblock > div.content { border-width: 0 0 0 3px; border-color: #E8E8E8; }
div.verseblock { border-left-width: 0; margin-left: 3em; }
div.quoteblock { border-left-width: 3px; margin-left: 0; margin-right: 0;}
div.admonitionblock td.content { border-left: 3px solid #E8E8E8; }
</style>
<script type="text/javascript">
/*<![CDATA[*/
var asciidoc = { // Namespace.
/////////////////////////////////////////////////////////////////////
// Table Of Contents generator
/////////////////////////////////////////////////////////////////////
/* Author: Mihai Bazon, September 2002
* http://students.infoiasi.ro/~mishoo
*
* Table Of Content generator
* Version: 0.4
*
* Feel free to use this script under the terms of the GNU General Public
* License, as long as you do not remove or alter this notice.
*/
/* modified by Troy D. Hanson, September 2006. License: GPL */
/* modified by Stuart Rackham, 2006, 2009. License: GPL */
// toclevels = 1..4.
toc: function (toclevels) {
function getText(el) {
var text = "";
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
text += i.data;
else if (i.firstChild != null)
text += getText(i);
}
return text;
}
function TocEntry(el, text, toclevel) {
this.element = el;
this.text = text;
this.toclevel = toclevel;
}
function tocEntries(el, toclevels) {
var result = new Array;
var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
if (!toc) {
return;
}
// Delete existing TOC entries in case we're reloading the TOC.
var tocEntriesToRemove = [];
var i;
for (i = 0; i < toc.childNodes.length; i++) {
var entry = toc.childNodes[i];
if (entry.nodeName.toLowerCase() == 'div'
&& entry.getAttribute("class")
&& entry.getAttribute("class").match(/^toclevel/))
tocEntriesToRemove.push(entry);
}
for (i = 0; i < tocEntriesToRemove.length; i++) {
toc.removeChild(tocEntriesToRemove[i]);
}
// Rebuild TOC entries.
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
// Delete existing footnote entries in case we're reloading the footnodes.
var i;
var noteholder = document.getElementById("footnotes");
if (!noteholder) {
return;
}
var entriesToRemove = [];
for (i = 0; i < noteholder.childNodes.length; i++) {
var entry = noteholder.childNodes[i];
if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
entriesToRemove.push(entry);
}
for (i = 0; i < entriesToRemove.length; i++) {
noteholder.removeChild(entriesToRemove[i]);
}
// Rebuild footnote entries.
var cont = document.getElementById("content");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
var note = spans[i].getAttribute("data-note");
if (!note) {
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
spans[i].setAttribute("data-note", note);
}
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
},
install: function(toclevels) {
var timerId;
function reinstall() {
asciidoc.footnotes();
if (toclevels) {
asciidoc.toc(toclevels);
}
}
function reinstallAndRemoveTimer() {
clearInterval(timerId);
reinstall();
}
timerId = setInterval(reinstall, 500);
if (document.addEventListener)
document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
else
window.onload = reinstallAndRemoveTimer;
}
}
asciidoc.install();
/*]]>*/
</script>
<style type="text/css">
body {
margin: 1em auto 1em auto;
padding: 0 1em 0 1em;
max-width: 800px;
}
a.image {
border: none;
}
.comments {
display: block;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAgCAYAAAB6kdqOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAB0wAAAdMBc2+PegAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAASjSURBVFiFvZdPaBxVHMc/b/7sbNLdxG13s0sbE1jBxELVbVGEgqmQiiBiDxZqKRWhR0Fqe/BSmoNQSNmrt4ISTyV3byWLHorVU5dYtgVpk4DGhXZ1a7rZmXkeMm99eZn9k1b9wY/3Z2f2fX7f3++9mRFSSnQTQgjAAkTkaO2zmtRaCYTSABBqrIEkS6VS9vTp069lMpmClFL4vt8BCsNwWwsQBAHm7+Y4CAKEEEGtVvtlYWHhbqvVagJ/AE90MCGlVDD2xYsXiydPnvza87wXksnk8NDQUFIPQPW7zfXyMAwJw5BGo/FXs9ncvHfv3tKFCxe+aLfbDyKwQEopFZBdLpdfnp2d/Tafz4+5rhsxghAC1d+h/y5gzH69XvdrtdqDs2fPfuT7/jLQkFIGlhBC5HK5oZmZmW8KhUI+kUgIy7KwLAvbtrFte1vfdHVtnKtg9L7yffv2OcViceLSpUufA88DSSGEcABrfn7+zdHR0UnXdWNv1tXqpY6phGVZnRoy/0MIQT6fdw4ePHgUKAK/AU8sQOzfv/+tdDq9x4xKd1MVU51uSvTzVCrlTU9PTwN7AGEBYmRk5FXXdTvk+gI6kJnGQQG6KQQwMjLiTk1NTQIJBQTgmAWst2rhfiBxC3ab00wAbtRugZjb2LzR3O7d2rh7+s2Ztg1IwajChK2DTSlggpuFrHs34H7BOHELqN0Rl5K4P+4GNQioPt8BUqeoqpd+MGYQvQ7DfrCxKVNAcTCws0B7RdrvhO4HtS1lCkYtbKrT7WB8GihdQf2B3FFIPbEH2cY6iAljjk1l4qB2KKSrMwjMblXqpVpfIF2lXjBxULsB06HigDb1lA2ijgm0WyithmS73faJ3iYdgHq9/tOBAwfe9jyvJ4wam1H1O196QT18+HBzeXl5FQgVkLxz5873k5OTzWw2m+oHE6dMHEw3EGBbuh4/fuyvrKysAS1AOkA4Nzf3w5EjR+6m0+mS/tTvBhMH1U2lXgqtra21l5aWvgNWgCYQ2tH/hY1G48epqal3Pc/b4ziOGLQegiCIPVv0ubhDcXV1dfP27dv3y+Xyl0AVqAO+/pKfmpiYeHFubm4+m82+kkgkPNd1nbjI9TaZTNqu61rRQpbrujiOs+O6MAx59OhRuL6+3mq1Wq1KpXJjYWFhMYK5DzSljF7yo7RYwBCQBfKlUml6bGxsMggCLwgC/Ruts4CRPpFMJodnZmbeKBaLLxUKheFMJmPr6a5Wq0+uXLmyWK1WK8DPwBrwO7AhpQxB+y6LoARbhe4Bw0AyGlv0N/Vd56VSqb3nzp378PDhw+/ncrnnCoWCZ1kWvu9z69at9fPnz3+6sbFxE/gVaEkNYhuQBqUvsBtTSnrAKDB25syZ944dO/ZxNpvNjY+PDzebTb9Sqdy8fPnyZ0AN+FOpEwv0rKYFZEdgaSB7/PjxoydOnPgkl8tNAN7169fLi4uLX7G1w/5RadDnz9N4pJbNVupzwHSpVPrg6tWrN65du/broUOHZoEMYHXu+S+BYsA8YC9QHB8ff/3UqVPvREC2uvZfT1kvi9KpNo7LVo1uApsqZf8rkAHWMX2X/Q1tcUY1hl3QyQAAAABJRU5ErkJggg==') top left no-repeat;
float: left;
margin-left: -55px;
width: 36px;
height: 48px;
line-height: 0;
color: black;
text-decoration: none !important;
border: none !important;
}
#toc .comments {
margin-top: 0.25em;
}
.sect1 .comments {
margin-top: 0.5em;
}
.sect2 .comments {
margin-top: 1.15em;
}
.sect3 .comments {
margin-top: -1em;
}
.comments.empty {
opacity: 0.2;
}
.comments.empty:hover,
.comments.nonempty {
opacity: 1;
}
.comments .count {
display: block;
font-size: 80%;
padding-top: 12px;
text-align: center;
text-shadow: 1px 1px 2px white;
}
#comments_lightbox_shadow {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: black;
opacity: 0.7;
z-index: 10;
}
#comments_lightbox_contents {
position: fixed;
top: 10%;
left: 20%;
right: 20%;
bottom: 10%;
background: white;
overflow: auto;
z-index: 11;
}
#comments_lightbox_contents > .shell {
margin: 2em;
}
pre {
overflow: auto;
}
@media print {
body {
font-size: 18pt;
}
#header h1 {
page-break-after: always;
font-size: 500%;
vertical-align: middle;
}
#header {
page-break-after: always;
}
#toctitle {
font-size: 200%;
margin-bottom: 1em;
}
div.toclevel1 {
font-size: 100%;
}
div.toclevel2 {
font-size: 90%;
}
div.toclevel3 {
font-size: 80%;
}
#content .comments {
display: none;
}
@page :left {
@bottom-left {
content: counter(page);
}
}
}
#topbar {
position: fixed;
left: 0;
top: 0;
right: 0;
height: 2.5em;
padding-left: 10%;
padding-right: 10%;
z-index: 1;
background: #880000;
overflow: hidden;
white-space: nowrap;
box-shadow: 0px 3px 6px #555555;
-moz-box-shadow: 0px 3px 6px #555555;
-webkit-box-shadow: 0px 3px 6px #555555;
-o-box-shadow: 0px 3px 6px #555555;
}
#topbar .title {
display: inline-block;
margin: 0.6em 1em 0 0;
vertical-align: top;
}
#topbar .title img {
display: none;
margin-right: 6px;
vertical-align: middle;
}
#topbar .title a {
color: #fffafa;
border: 0;
}
#topbar .title:hover img,
.mobile #topbar .title img {
display: inline-block;
margin-left: -17px;
}
#topbar .title:hover a,
.mobile #topbar .title a {
color: #ffffdd;
}
#floattoc {
position: fixed;
z-index: 1;
top: 2em;
bottom: 20%;
width: 50%;
background: #f0f0f0;
color: black;
box-shadow: 0px 6px 6px #555555;
-moz-box-shadow: 0px 6px 6px #555555;
-webkit-box-shadow: 0px 6px 6px #555555;
-o-box-shadow: 0px 6px 6px #555555;
overflow: auto;
padding: 1em;
border-radius: 6px;
-webkit-border-radius: 8px;
-webkit-border-top-left-radius: 0;
-webkit-border-top-right-radius: 0;
-moz-border-radius: 8px;
-moz-border-radius-topleft: 0;
-moz-border-top-right-radius: 0;
-o-border-radius: 8px;
-o-border-radius-topleft: 0;
-o-border-top-right-radius: 0;
border-radius: 8px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
#floattoc a.current {
font-weight: bold;
color: black;
}
#current_section {
display: inline-block;
margin: 0.5em 0 0 0;
padding: 0.2em 0.5em 0.2em 0.5em;
background: #550000;
font-size: 90%;
vertical-align: top;
color: white;
border: none;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
-o-border-radius: 8px;
border-radius: 8px;
}
#current_section:hover {
text-decoration: none;
border: none;
}
#current_section.pressed {
background: #f0f0f0;
color: black;
-webkit-border-top-left-radius: 8px;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-left-radius: 0;
-webkit-border-bottom-right-radius: 0;
-moz-border-radius-topleft: 8px;
-moz-border-radius-topright: 8px;
-moz-border-bottom-left-radius: 0;
-moz-border-bottom-right-radius: 0;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
/* http://nicolasgallagher.com/jump-links-and-viewport-positioning/ */
.anchor_helper {
position: relative;
display: block;
top: -50px;
width: 1px;
height: 1px;
}
</style>
</head>
<body class="article">
<div id="topbar" style="display: none">
<div class="title">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAKAgMAAAFomXyGAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sGCRMSACDxkZwAAAAidEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVAgb24gYSBNYWOHqHdDAAAADFBMVEX////////////////1pQ5zAAAAA3RSTlMAM3/Op81DAAAAAWJLR0QDEQxM8gAAADVJREFUCB0FwcENgCAQALAm+CIkbqK3AaPBZjKSD54mZ4vAEgivyj0dNC46zyTwUZIzl5H7B9S6CyQSx+f8AAAAAElFTkSuQmCC" width="11" height="10" alt="">
<a href="javascript:void(Mizuho.smoothlyScrollToToc())">Phusion Passenger users guide, Apache version</a>
</div>
<a href="javascript:void(0)" id="current_section"></a>
</div>
<div id="header">
<h1>Phusion Passenger users guide, Apache version</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png">
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is an application server which can directly integrate into Apache. It is designed to be easy to use, fast, stable and reliable and is used by <a href="http://trends.builtwith.com/Web-Server/Phusion-Passenger">hundreds of thousands of websites</a> all over the world.</p></div>
<div class="paragraph"><p>Phusion Passenger is a so-called polyglot application server because it supports applications written in multiple programming languages. At this time, Ruby and Python are supported.</p></div>
<div class="paragraph"><p>This users guide will teach you:</p></div>
<div class="ulist"><ul>
<li>
<p>
How to install Phusion Passenger.
</p>
</li>
<li>
<p>
How to configure Phusion Passenger.
</p>
</li>
<li>
<p>
How to deploy Ruby and Python applications.
</p>
</li>
<li>
<p>
How to solve common problems.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This guide assumes that the reader is somewhat familiar with Apache and with
using the command line.</p></div>
</div>
</div>
<div id="toc">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><div id="toctitle">Table of Contents</div>
<div class="foo toclevel2"><a href="#_support_information">1. Support information</a></div>
<div class="foo toclevel3"><a href="#_supported_operating_systems">1.1. Supported operating systems</a></div>
<div class="foo toclevel3"><a href="#where_to_get_support">1.2. Where to get support</a></div>
<div class="foo toclevel2"><a href="#installation">2. Installation</a></div>
<div class="foo toclevel3"><a href="#_synopsis">2.1. Synopsis</a></div>
<div class="foo toclevel3"><a href="#install_osx_homebrew">2.2. Installing or upgrading on Mac OS X with Homebrew</a></div>
<div class="foo toclevel3"><a href="#install_on_debian_ubuntu">2.3. Installing or upgrading on Debian or Ubuntu</a></div>
<div class="foo toclevel4"><a href="#install_add_apt_repo">2.3.1. Adding our APT repository</a></div>
<div class="foo toclevel4"><a href="#_installing_packages">2.3.2. Installing packages</a></div>
<div class="foo toclevel3"><a href="#_installing_or_upgrading_on_red_hat_fedora_centos_or_scientificlinux">2.4. Installing or upgrading on Red Hat, Fedora, CentOS or ScientificLinux</a></div>
<div class="foo toclevel3"><a href="#rubygems_generic_install">2.5. Generic installation, upgrade and downgrade method: via RubyGems</a></div>
<div class="foo toclevel3"><a href="#tarball_generic_install">2.6. Generic installation, upgrade and downgrade method: via tarball</a></div>
<div class="foo toclevel3"><a href="#_upgrading_from_open_source_to_enterprise">2.7. Upgrading from open source to Enterprise</a></div>
<div class="foo toclevel3"><a href="#_cryptographic_verification_of_installation_files">2.8. Cryptographic verification of installation files</a></div>
<div class="foo toclevel4"><a href="#_synopsis_2">2.8.1. Synopsis</a></div>
<div class="foo toclevel4"><a href="#_importing_the_phusion_software_signing_key">2.8.2. Importing the Phusion Software Signing key</a></div>
<div class="foo toclevel4"><a href="#_verifying_the_phusion_software_signing_key">2.8.3. Verifying the Phusion Software Signing key</a></div>
<div class="foo toclevel4"><a href="#_verifying_the_gem_and_tarball">2.8.4. Verifying the gem and tarball</a></div>
<div class="foo toclevel4"><a href="#_verifying_git_signatures">2.8.5. Verifying Git signatures</a></div>
<div class="foo toclevel4"><a href="#_verifying_deb_and_rpm_packages">2.8.6. Verifying DEB and RPM packages</a></div>
<div class="foo toclevel4"><a href="#_revocation">2.8.7. Revocation</a></div>
<div class="foo toclevel3"><a href="#_non_interactive_automatic_headless_installs_or_upgrades">2.9. Non-interactive, automatic, headless installs or upgrades</a></div>
<div class="foo toclevel3"><a href="#_customizing_the_compilation_process">2.10. Customizing the compilation process</a></div>
<div class="foo toclevel4"><a href="#_setting_the_compiler">2.10.1. Setting the compiler</a></div>
<div class="foo toclevel4"><a href="#_adding_additional_compiler_or_linker_flags">2.10.2. Adding additional compiler or linker flags</a></div>
<div class="foo toclevel4"><a href="#forcing_location_of_command_line_tools_and_dependencies">2.10.3. Forcing location of command line tools and dependencies</a></div>
<div class="foo toclevel3"><a href="#multiple_apache_installs">2.11. Dealing with multiple Apache installations</a></div>
<div class="foo toclevel3"><a href="#working_with_apache_conf">2.12. Working with the Apache configuration file</a></div>
<div class="foo toclevel3"><a href="#_disabling_without_uninstalling">2.13. Disabling without uninstalling</a></div>
<div class="foo toclevel3"><a href="#uninstalling">2.14. Uninstalling</a></div>
<div class="foo toclevel3"><a href="#moving_phusion_passenger">2.15. Moving to a different directory</a></div>
<div class="foo toclevel2"><a href="#_deploying_a_ruby_on_rails_1_x_or_2_x_but_not_rails_gt_3_x_application">3. Deploying a Ruby on Rails 1.x or 2.x (but NOT Rails >= 3.x) application</a></div>
<div class="foo toclevel3"><a href="#_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host’s root</a></div>
<div class="foo toclevel3"><a href="#deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</a></div>
<div class="foo toclevel3"><a href="#_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</a></div>
<div class="foo toclevel3"><a href="#_migrations">3.4. Migrations</a></div>
<div class="foo toclevel3"><a href="#_capistrano_integration">3.5. Capistrano integration</a></div>
<div class="foo toclevel2"><a href="#_deploying_a_rack_based_ruby_application_including_rails_gt_3">4. Deploying a Rack-based Ruby application (including Rails >= 3)</a></div>
<div class="foo toclevel3"><a href="#_tutorial_example_writing_and_deploying_a_hello_world_rack_application">4.1. Tutorial/example: writing and deploying a Hello World Rack application</a></div>
<div class="foo toclevel3"><a href="#_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host’s root</a></div>
<div class="foo toclevel3"><a href="#deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</a></div>
<div class="foo toclevel3"><a href="#_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</a></div>
<div class="foo toclevel3"><a href="#_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</a></div>
<div class="foo toclevel4"><a href="#_camping">4.5.1. Camping</a></div>
<div class="foo toclevel4"><a href="#_halcyon">4.5.2. Halcyon</a></div>
<div class="foo toclevel4"><a href="#_mack">4.5.3. Mack</a></div>
<div class="foo toclevel4"><a href="#_merb">4.5.4. Merb</a></div>
<div class="foo toclevel4"><a href="#_ramaze">4.5.5. Ramaze</a></div>
<div class="foo toclevel4"><a href="#_sinatra">4.5.6. Sinatra</a></div>
<div class="foo toclevel2"><a href="#_deploying_a_wsgi_python_application">5. Deploying a WSGI (Python) application</a></div>
<div class="foo toclevel3"><a href="#_tutorial_example_writing_and_deploying_a_hello_world_wsgi_application">5.1. Tutorial/example: writing and deploying a Hello World WSGI application</a></div>
<div class="foo toclevel3"><a href="#_deploying_to_a_virtual_host_8217_s_root_3">5.2. Deploying to a virtual host’s root</a></div>
<div class="foo toclevel3"><a href="#deploying_python_to_sub_uri">5.3. Deploying to a sub URI</a></div>
<div class="foo toclevel3"><a href="#_redeploying_restarting_the_wsgi_application">5.4. Redeploying (restarting the WSGI application)</a></div>
<div class="foo toclevel2"><a href="#_deploying_a_node_js_application">6. Deploying a Node.js application</a></div>
<div class="foo toclevel2"><a href="#_deploying_a_meteor_application">7. Deploying a Meteor application</a></div>
<div class="foo toclevel2"><a href="#_configuring_phusion_passenger">8. Configuring Phusion Passenger</a></div>
<div class="foo toclevel3"><a href="#_passengerroot_lt_directory_gt">8.1. PassengerRoot <directory></a></div>
<div class="foo toclevel3"><a href="#PassengerDefaultRuby">8.2. PassengerDefaultRuby <filename></a></div>
<div class="foo toclevel3"><a href="#_deployment_options">8.3. Deployment options</a></div>
<div class="foo toclevel4"><a href="#PassengerEnabled">8.3.1. PassengerEnabled <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerRuby">8.3.2. PassengerRuby <filename></a></div>
<div class="foo toclevel4"><a href="#_passengerpython_lt_filename_gt">8.3.3. PassengerPython <filename></a></div>
<div class="foo toclevel4"><a href="#_passengernodejs_lt_filename_gt">8.3.4. PassengerNodejs <filename></a></div>
<div class="foo toclevel4"><a href="#PassengerAppEnv">8.3.5. PassengerAppEnv <string></a></div>
<div class="foo toclevel4"><a href="#rails_env">8.3.6. RailsEnv <string></a></div>
<div class="foo toclevel4"><a href="#rack_env">8.3.7. RackEnv <string></a></div>
<div class="foo toclevel4"><a href="#PassengerAppRoot">8.3.8. PassengerAppRoot <path/to/root></a></div>
<div class="foo toclevel4"><a href="#PassengerBaseURI">8.3.9. PassengerBaseURI <uri></a></div>
<div class="foo toclevel4"><a href="#_passengerrestartdir_lt_directory_gt">8.3.10. PassengerRestartDir <directory></a></div>
<div class="foo toclevel4"><a href="#PassengerRollingRestarts">8.3.11. PassengerRollingRestarts <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerResistDeploymentErrors">8.3.12. PassengerResistDeploymentErrors <on|off></a></div>
<div class="foo toclevel3"><a href="#_process_spawning_options">8.4. Process spawning options</a></div>
<div class="foo toclevel4"><a href="#PassengerSpawnMethod">8.4.1. PassengerSpawnMethod <string></a></div>
<div class="foo toclevel4"><a href="#PassengerLoadShellEnvvars">8.4.2. PassengerLoadShellEnvvars <on|off></a></div>
<div class="foo toclevel3"><a href="#_security_options">8.5. Security options</a></div>
<div class="foo toclevel4"><a href="#PassengerUserSwitching">8.5.1. PassengerUserSwitching <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerUser">8.5.2. PassengerUser <username></a></div>
<div class="foo toclevel4"><a href="#PassengerGroup">8.5.3. PassengerGroup <group name></a></div>
<div class="foo toclevel4"><a href="#PassengerDefaultUser">8.5.4. PassengerDefaultUser <username></a></div>
<div class="foo toclevel4"><a href="#PassengerDefaultGroup">8.5.5. PassengerDefaultGroup <group name></a></div>
<div class="foo toclevel4"><a href="#PassengerFriendlyErrorPages">8.5.6. PassengerFriendlyErrorPages <on|off></a></div>
<div class="foo toclevel3"><a href="#_resource_control_and_optimization_options">8.6. Resource control and optimization options</a></div>
<div class="foo toclevel4"><a href="#PassengerMaxPoolSize">8.6.1. PassengerMaxPoolSize <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerMinInstances">8.6.2. PassengerMinInstances <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerMaxInstances">8.6.3. PassengerMaxInstances <integer></a></div>
<div class="foo toclevel4"><a href="#_passengermaxinstancesperapp_lt_integer_gt">8.6.4. PassengerMaxInstancesPerApp <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerPoolIdleTime">8.6.5. PassengerPoolIdleTime <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerMaxPreloaderIdleTime">8.6.6. PassengerMaxPreloaderIdleTime <integer></a></div>
<div class="foo toclevel4"><a href="#_passengerstarttimeout_lt_seconds_gt">8.6.7. PassengerStartTimeout <seconds></a></div>
<div class="foo toclevel4"><a href="#PassengerConcurrencyModel">8.6.8. PassengerConcurrencyModel <process|thread></a></div>
<div class="foo toclevel4"><a href="#PassengerThreadCount">8.6.9. PassengerThreadCount <number></a></div>
<div class="foo toclevel4"><a href="#PassengerMaxRequests">8.6.10. PassengerMaxRequests <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerMaxRequestTime">8.6.11. PassengerMaxRequestTime <seconds></a></div>
<div class="foo toclevel4"><a href="#PassengerMemoryLimit">8.6.12. PassengerMemoryLimit <integer></a></div>
<div class="foo toclevel4"><a href="#_passengerstatthrottlerate_lt_integer_gt">8.6.13. PassengerStatThrottleRate <integer></a></div>
<div class="foo toclevel4"><a href="#PassengerPreStart">8.6.14. PassengerPreStart <url></a></div>
<div class="foo toclevel4"><a href="#PassengerHighPerformance">8.6.15. PassengerHighPerformance <on|off></a></div>
<div class="foo toclevel3"><a href="#_connection_handling_options">8.7. Connection handling options</a></div>
<div class="foo toclevel4"><a href="#PassengerBufferUpload">8.7.1. PassengerBufferUpload <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerBufferResponse">8.7.2. PassengerBufferResponse <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerErrorOverride">8.7.3. PassengerErrorOverride <on|off></a></div>
<div class="foo toclevel4"><a href="#PassengerMaxRequestQueueSize">8.7.4. PassengerMaxRequestQueueSize <number></a></div>
<div class="foo toclevel3"><a href="#_compatibility_options">8.8. Compatibility options</a></div>
<div class="foo toclevel4"><a href="#PassengerResolveSymlinksInDocumentRoot">8.8.1. PassengerResolveSymlinksInDocumentRoot <on|off></a></div>
<div class="foo toclevel4"><a href="#_passengerallowencodedslashes_lt_on_off_gt">8.8.2. PassengerAllowEncodedSlashes <on|off></a></div>
<div class="foo toclevel3"><a href="#_logging_and_debugging_options">8.9. Logging and debugging options</a></div>
<div class="foo toclevel4"><a href="#PassengerLogLevel">8.9.1. PassengerLogLevel <integer></a></div>
<div class="foo toclevel4"><a href="#_passengerdebuglogfile_lt_filename_gt">8.9.2. PassengerDebugLogFile <filename></a></div>
<div class="foo toclevel4"><a href="#_passengerdebugger_lt_on_off_gt">8.9.3. PassengerDebugger <on|off></a></div>
<div class="foo toclevel3"><a href="#_advanced_options">8.10. Advanced options</a></div>
<div class="foo toclevel4"><a href="#PassengerTempDir">8.10.1. PassengerTempDir <directory></a></div>
<div class="foo toclevel4"><a href="#PassengerUploadBufferDir">8.10.2. PassengerUploadBufferDir <directory></a></div>
<div class="foo toclevel3"><a href="#_deprecated_or_removed_options">8.11. Deprecated or removed options</a></div>
<div class="foo toclevel4"><a href="#_railsruby">8.11.1. RailsRuby</a></div>
<div class="foo toclevel4"><a href="#_railsbaseuri_and_rackbaseuri">8.11.2. RailsBaseURI and RackBaseURI</a></div>
<div class="foo toclevel4"><a href="#_railsuserswitching">8.11.3. RailsUserSwitching</a></div>
<div class="foo toclevel4"><a href="#_railsdefaultuser">8.11.4. RailsDefaultUser</a></div>
<div class="foo toclevel4"><a href="#_railsallowmodrewrite">8.11.5. RailsAllowModRewrite</a></div>
<div class="foo toclevel4"><a href="#_railsspawnmethod">8.11.6. RailsSpawnMethod</a></div>
<div class="foo toclevel4"><a href="#_railsautodetect_rackautodetect_and_wsgiautodetect">8.11.7. RailsAutoDetect, RackAutoDetect and WsgiAutoDetect</a></div>
<div class="foo toclevel4"><a href="#_railsappspawneridletime">8.11.8. RailsAppSpawnerIdleTime</a></div>
<div class="foo toclevel4"><a href="#_railsframeworkspawneridletime">8.11.9. RailsFrameworkSpawnerIdleTime</a></div>
<div class="foo toclevel2"><a href="#troubleshooting">9. Troubleshooting</a></div>
<div class="foo toclevel3"><a href="#_generic_troubleshooting_tips">9.1. Generic troubleshooting tips</a></div>
<div class="foo toclevel3"><a href="#_why_does_the_first_request_take_a_long_time">9.2. Why does the first request take a long time?</a></div>
<div class="foo toclevel3"><a href="#_os_x_the_installer_cannot_locate_mamp_8217_s_apache">9.3. OS X: The installer cannot locate MAMP’s Apache</a></div>
<div class="foo toclevel3"><a href="#_apache_reports_a_403_forbidden_error">9.4. Apache reports a "403 Forbidden" error</a></div>
<div class="foo toclevel3"><a href="#_static_assets_such_as_images_and_stylesheets_aren_8217_t_being_displayed">9.5. Static assets such as images and stylesheets aren’t being displayed</a></div>
<div class="foo toclevel3"><a href="#_the_apache_error_log_says_that_the_spawn_manager_script_does_not_exist_or_that_it_does_not_have_permission_to_execute_it">9.6. The Apache error log says that the spawn manager script does not exist, or that it does not have permission to execute it</a></div>
<div class="foo toclevel3"><a href="#_the_application_thinks_its_not_on_ssl_even_though_it_is">9.7. The application thinks its not on SSL even though it is</a></div>
<div class="foo toclevel3"><a href="#_ruby_on_rails_specific_troubleshooting">9.8. Ruby on Rails-specific troubleshooting</a></div>
<div class="foo toclevel4"><a href="#_the_about_your_application_8217_s_environment_link_does_not_work">9.8.1. The "About your application’s environment" link does not work</a></div>
<div class="foo toclevel4"><a href="#_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error">9.8.2. The Rails application reports that it’s unable to start because of a permission error</a></div>
<div class="foo toclevel4"><a href="#_the_rails_application_8217_s_log_file_is_not_being_written_to">9.8.3. The Rails application’s log file is not being written to</a></div>
<div class="foo toclevel3"><a href="#conflicting_apache_modules">9.9. Conflicting Apache modules</a></div>
<div class="foo toclevel4"><a href="#_mod_userdir">9.9.1. mod_userdir</a></div>
<div class="foo toclevel4"><a href="#_multiviews_mod_negotiation">9.9.2. MultiViews (mod_negotiation)</a></div>
<div class="foo toclevel4"><a href="#_virtualdocumentroot">9.9.3. VirtualDocumentRoot</a></div>
<div class="foo toclevel2"><a href="#_analysis_and_system_maintenance">10. Analysis and system maintenance</a></div>
<div class="foo toclevel3"><a href="#_inspecting_memory_usage">10.1. Inspecting memory usage</a></div>
<div class="foo toclevel3"><a href="#_inspecting_phusion_passenger_8217_s_internal_status">10.2. Inspecting Phusion Passenger’s internal status</a></div>
<div class="foo toclevel3"><a href="#debugging_frozen">10.3. Debugging frozen applications</a></div>
<div class="foo toclevel3"><a href="#_accessing_individual_application_processes">10.4. Accessing individual application processes</a></div>
<div class="foo toclevel3"><a href="#_attaching_an_irb_console_to_an_application_process">10.5. Attaching an IRB console to an application process</a></div>
<div class="foo toclevel2"><a href="#_tips">11. Tips</a></div>
<div class="foo toclevel3"><a href="#user_switching">11.1. User Switching (security feature)</a></div>
<div class="foo toclevel4"><a href="#_requirements">11.1.1. Requirements</a></div>
<div class="foo toclevel4"><a href="#_effects">11.1.2. Effects</a></div>
<div class="foo toclevel4"><a href="#_caveats_amp_troubleshooting">11.1.3. Caveats & troubleshooting</a></div>
<div class="foo toclevel4"><a href="#finding_out_app_user">11.1.4. Finding out what user an application is running as</a></div>
<div class="foo toclevel3"><a href="#reducing_memory_usage">11.2. Copy-on-write memory support (reducing memory consumption of Ruby applications)</a></div>
<div class="foo toclevel3"><a href="#capistrano">11.3. Capistrano recipe</a></div>
<div class="foo toclevel3"><a href="#bundler_support">11.4. Bundler support</a></div>
<div class="foo toclevel4"><a href="#add_passenger_to_gemfile">11.4.1. Does Phusion Passenger itself need to be added to the Gemfile?</a></div>
<div class="foo toclevel3"><a href="#_installing_multiple_ruby_on_rails_versions">11.5. Installing multiple Ruby on Rails versions</a></div>
<div class="foo toclevel3"><a href="#_making_the_application_restart_after_each_request">11.6. Making the application restart after each request</a></div>
<div class="foo toclevel3"><a href="#sub_uri_deployment_uri_fix">11.7. How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</a></div>
<div class="foo toclevel3"><a href="#_out_of_band_work_and_out_of_band_garbage_collection">11.8. Out-of-Band Work and Out-of-Band Garbage Collection</a></div>
<div class="foo toclevel3"><a href="#_hooks">11.9. Hooks</a></div>
<div class="foo toclevel4"><a href="#_example">11.9.1. Example</a></div>
<div class="foo toclevel4"><a href="#_environment">11.9.2. Environment</a></div>
<div class="foo toclevel4"><a href="#_blocking_and_concurrency">11.9.3. Blocking and concurrency</a></div>
<div class="foo toclevel4"><a href="#_error_handling">11.9.4. Error handling</a></div>
<div class="foo toclevel4"><a href="#_compatibility">11.9.5. Compatibility</a></div>
<div class="foo toclevel4"><a href="#_available_hooks">11.9.6. Available hooks</a></div>
<div class="foo toclevel3"><a href="#flying_passenger">11.10. Flying Passenger</a></div>
<div class="foo toclevel4"><a href="#_requirements_2">11.10.1. Requirements</a></div>
<div class="foo toclevel4"><a href="#_basic_usage">11.10.2. Basic usage</a></div>
<div class="foo toclevel4"><a href="#configuring_flying_passenger">11.10.3. Configuring Flying Passenger</a></div>
<div class="foo toclevel4"><a href="#_managing_the_flying_passenger_daemon">11.10.4. Managing the Flying Passenger daemon</a></div>
<div class="foo toclevel4"><a href="#using_flying_passenger_with_mri_18_or_jruby">11.10.5. Using Flying Passenger with MRI 1.8 or JRuby</a></div>
<div class="foo toclevel4"><a href="#flying_passenger_caveats">11.10.6. Caveats and limitations</a></div>
<div class="foo toclevel3"><a href="#_x_sendfile_support">11.11. X-Sendfile support</a></div>
<div class="foo toclevel3"><a href="#_upload_progress">11.12. Upload progress</a></div>
<div class="foo toclevel2"><a href="#_under_the_hood">12. Under the hood</a></div>
<div class="foo toclevel3"><a href="#_page_caching_support">12.1. Page caching support</a></div>
<div class="foo toclevel3"><a href="#relationship_with_ruby">12.2. Phusion Passenger and its relationship with Ruby</a></div>
<div class="foo toclevel4"><a href="#_how_ruby_is_used">12.2.1. How Ruby is used</a></div>
<div class="foo toclevel4"><a href="#_when_the_system_has_multiple_ruby_interpreters">12.2.2. When the system has multiple Ruby interpreters</a></div>
<div class="foo toclevel3"><a href="#_static_assets_serving">12.3. Static assets serving</a></div>
<div class="foo toclevel3"><a href="#application_detection">12.4. How Phusion Passenger detects whether a virtual host is a web application</a></div>
<div class="foo toclevel2"><a href="#_appendix_a_about_this_document">13. Appendix A: About this document</a></div>
<div class="foo toclevel2"><a href="#_appendix_b_terminology">14. Appendix B: Terminology</a></div>
<div class="foo toclevel3"><a href="#application_root">14.1. Application root</a></div>
<div class="foo toclevel3"><a href="#idle_process">14.2. Idle process</a></div>
<div class="foo toclevel3"><a href="#inactive_process">14.3. Inactive process</a></div>
<div class="foo toclevel2"><a href="#spawning_methods_explained">15. Appendix C: Spawning methods explained</a></div>
<div class="foo toclevel3"><a href="#_the_most_straightforward_and_traditional_way_direct_spawning">15.1. The most straightforward and traditional way: direct spawning</a></div>
<div class="foo toclevel3"><a href="#_the_smart_spawning_method">15.2. The smart spawning method</a></div>
<div class="foo toclevel4"><a href="#_how_it_works">15.2.1. How it works</a></div>
<div class="foo toclevel4"><a href="#_summary_of_benefits">15.2.2. Summary of benefits</a></div>
<div class="foo toclevel3"><a href="#_smart_spawning_gotcha_1_unintentional_file_descriptor_sharing">15.3. Smart spawning gotcha #1: unintentional file descriptor sharing</a></div>
<div class="foo toclevel4"><a href="#_example_1_memcached_connection_sharing_harmful">15.3.1. Example 1: Memcached connection sharing (harmful)</a></div>
<div class="foo toclevel4"><a href="#_example_2_log_file_sharing_not_harmful">15.3.2. Example 2: Log file sharing (not harmful)</a></div>
<div class="foo toclevel3"><a href="#_smart_spawning_gotcha_2_the_need_to_revive_threads">15.4. Smart spawning gotcha #2: the need to revive threads</a></div>
<div class="foo toclevel3"><a href="#_smart_spawning_gotcha_3_code_load_order">15.5. Smart spawning gotcha #3: code load order</a></div>
<div class="foo toclevel2"><a href="#about_environment_variables">16. Appendix D: About environment variables</a></div>
<div class="foo toclevel3"><a href="#_working_with_environment_variables">16.1. Working with environment variables</a></div>
<div class="foo toclevel3"><a href="#_the_path_environment_variable">16.2. The PATH environment variable</a></div>
<div class="foo toclevel4"><a href="#_adding_phusion_passenger_8217_s_administration_tools_to_path">16.2.1. Adding Phusion Passenger’s administration tools to PATH</a></div>
<div class="foo toclevel3"><a href="#_making_environment_variables_permanent">16.3. Making environment variables permanent</a></div>
<div class="foo toclevel4"><a href="#_bash">16.3.1. bash</a></div>
<div class="foo toclevel4"><a href="#_apache">16.3.2. Apache</a></div>
<div class="foo toclevel4"><a href="#_nginx">16.3.3. Nginx</a></div>
<div class="foo toclevel4"><a href="#_cron">16.3.4. cron</a></div>
<div class="foo toclevel4"><a href="#env_vars_passenger_apps">16.3.5. Phusion Passenger-served apps</a></div>
<div class="foo toclevel3"><a href="#env_vars_and_sudo">16.4. Environment variables and sudo</a></div>
</div>
</div>
<div id="content">
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_support_information"></span><h2 data-comment-topic="support-information-zkewk3" data-anchor="_support_information">1. Support information</h2>
<div class="sectionbody">
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_supported_operating_systems"></span><h3 data-comment-topic="supported-operating-systems-rhbg35" data-anchor="_supported_operating_systems">1.1. Supported operating systems</h3>
<div class="paragraph"><p>Phusion Passenger works on any POSIX-compliant operating system. In other
words: practically any operating system on earth, except Microsoft Windows.</p></div>
<div class="paragraph"><p>Phusion Passenger is confirmed on a large number of operating systems and Linux
distributions, including, but not limited to, Ubuntu, Debian, CentOS/Fedora/RHEL,
Gentoo, Mac OS X, FreeBSD and Solaris. OpenBSD is supported since version 5.2.
Both 32-bit and 64-bit platforms are supported.</p></div>
<div class="paragraph"><p>Please
<a href="http://code.google.com/p/phusion-passenger/issues/list">report a bug</a>
or
<a href="http://groups.google.com/group/phusion-passenger">join our discussion forum</a>
if it doesn’t work on your POSIX-compliant operating system.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="where_to_get_support"></span><h3 data-comment-topic="where-to-get-support-f3pbrb" data-anchor="where_to_get_support">1.2. Where to get support</h3>
<div class="ulist"><ul>
<li>
<p>
<a href="http://groups.google.com/group/phusion-passenger">Community discussion forum</a> - post a
message here if you’re experiencing problems. Support on this forum is provided by the community on a best-effort basis, so a (timely) response is not guaranteed.
</p>
</li>
<li>
<p>
<a href="http://code.google.com/p/phusion-passenger/issues/list">Issue tracker</a> - report
bugs here.
</p>
</li>
<li>
<p>
Email <a href="mailto:support@phusion.nl">support@phusion.nl</a> if you are a <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a> customer. Please mention your order reference. If you are not an Enterprise customer, we kindly redirect you to the community discussion forum instead.
</p>
</li>
<li>
<p>
<a href="https://www.phusionpassenger.com/commercial_support">Commercial support contracts</a> are also available.
</p>
</li>
<li>
<p>
Report security vulnerabilities to <a href="mailto:security@phusion.nl">security@phusion.nl</a>. We will do our best to respond to you as quickly as we can, so please do not disclose the vulnerability until then.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Please consult <a href="https://www.phusionpassenger.com/support">the Phusion Passenger website</a> for a full list of support resources.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="installation"></span><h2 data-comment-topic="installing-upgrading-and-uninstalling-phusion-passenger-laryvs" data-anchor="installation">2. Installation</h2>
<div class="sectionbody">
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_synopsis"></span><h3 data-comment-topic="synopsis-l0om5d" data-anchor="_synopsis">2.1. Synopsis</h3>
<div class="paragraph"><p>Because Phusion Passenger is designed to run in a wide variety of operating systems and configurations, there are multiple ways to install it. Most users — especially first-time users — will prefer <em>OS-specific installation instructions</em>. These are not only the easiest, but also allow Phusion Passenger to integrate into the operating system in the best way possible. Other users should consult the <em>generic installation instructions</em>.</p></div>
<div class="paragraph"><p>The steps for upgrading or downgrading Phusion Passenger is almost the same as the steps for installing. All the installation guides in this section will also teach you how to upgrade and downgrade.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="install_osx_homebrew"></span><h3 data-comment-topic="installing-or-upgrading-on-mac-os-x-with-homebrew-1pia1cx" data-anchor="install_osx_homebrew">2.2. Installing or upgrading on Mac OS X with Homebrew</h3>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Open source</strong>
</dt>
<dd>
<p>
Every time we release a new Phusion Passenger version, we make it available through <a href="http://brew.sh/">Homebrew</a>. Please note that the Homebrew maintainers have to merge our pull requests manually, so it may take a day or two before a new version shows up in the official Homebrew repository.
</p>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Update the Homebrew recipes:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>brew update</pre>
</div>
</div>
</li>
<li>
<p>
Run one of the following, and follow the instructions:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>brew install passenger
-OR-
brew upgrade passenger</pre>
</div>
</div>
</li>
</ol></div>
</dd>
<dt class="hdlist1">
<strong>Enterprise</strong>
</dt>
<dd>
<p>
<a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a> is currently not available through Homebrew. Please try one of the other installation methods instead.
</p>
</dd>
</dl></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="install_on_debian_ubuntu"></span><h3 data-comment-topic="installing-or-upgrading-on-ubuntu-1xg22xs" data-anchor="install_on_debian_ubuntu">2.3. Installing or upgrading on Debian or Ubuntu</h3>
<div class="paragraph"><p>We provide and official Phusion Passenger APT repository. This APT repository contains Phusion Passenger packages for multiple versions of Debian and Ubuntu. These packages are automatically built by our build server after we push out a source release, and thus are always up to date with the official source releases.</p></div>
<div class="paragraph"><p>If you use these packages to install Phusion Passenger then you do not need to run <span class="monospaced">passenger-install-apache2-module</span> or <span class="monospaced">passenger-install-nginx-module</span>. These packages contain all the binaries that you need.</p></div>
<div class="paragraph"><p>Packages are available for the x86 and x86_64 architectures. Our policy is to support all Ubuntu LTS releases that are still supported by Canonical, plus the latest non-LTS Ubuntu release, plus all Debian releases that are still supported by Debian.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="install_add_apt_repo"></span><h4 data-comment-topic="adding-our-apt-repository-1l8plxk" data-anchor="install_add_apt_repo">2.3.1. Adding our APT repository</h4>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Install our PGP key. Packages are signed by "Phusion Automated Software Signing (<a href="mailto:auto-software-signing@phusion.nl">auto-software-signing@phusion.nl</a>)", fingerprint 1637 8A33 A6EF 1676 2922 526E 561F 9B9C AC40 B2F7.
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7</pre>
</div>
</div>
</li>
<li>
<p>
Add HTTPS support for APT. Our APT repository is stored on an HTTPS server.
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo apt-get install apt-transport-https ca-certificates</pre>
</div>
</div>
</li>
<li>
<p>
Create a file <span class="monospaced">/etc/apt/sources.list.d/passenger.list</span> and insert <strong>one of</strong> the following lines, depending on your distribution.
</p>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Open source</strong>
</dt>
<dd>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">##### !!!! Only add ONE of these lines, not all of them !!!! #####</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 13.10</span></span>
deb https<span style="color: #990000">:</span>//oss-binaries<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/apt/passenger saucy main
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 12.04</span></span>
deb https<span style="color: #990000">:</span>//oss-binaries<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/apt/passenger precise main
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 10.04</span></span>
deb https<span style="color: #990000">:</span>//oss-binaries<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/apt/passenger lucid main
<span style="font-style: italic"><span style="color: #9A1900"># Debian 7</span></span>
deb https<span style="color: #990000">:</span>//oss-binaries<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/apt/passenger wheezy main
<span style="font-style: italic"><span style="color: #9A1900"># Debian 6</span></span>
deb https<span style="color: #990000">:</span>//oss-binaries<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/apt/passenger squeeze main</tt></pre>
</div>
</div>
</dd>
<dt class="hdlist1">
<strong>Enterprise</strong>
</dt>
<dd>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">##### !!!! Only add ONE of these lines, not all of them !!!! #####</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 13.10</span></span>
deb https<span style="color: #990000">:</span>//download<span style="color: #990000">:</span>YOUR_DOWNLOAD_TOKEN@www<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/enterprise_apt saucy main
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 12.04</span></span>
deb https<span style="color: #990000">:</span>//download<span style="color: #990000">:</span>YOUR_DOWNLOAD_TOKEN@www<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/enterprise_apt precise main
<span style="font-style: italic"><span style="color: #9A1900"># Ubuntu 10.04</span></span>
deb https<span style="color: #990000">:</span>//download<span style="color: #990000">:</span>YOUR_DOWNLOAD_TOKEN@www<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/enterprise_apt lucid main
<span style="font-style: italic"><span style="color: #9A1900"># Debian 7</span></span>
deb https<span style="color: #990000">:</span>//download<span style="color: #990000">:</span>YOUR_DOWNLOAD_TOKEN@www<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/enterprise_apt wheezy main
<span style="font-style: italic"><span style="color: #9A1900"># Debian 6</span></span>
deb https<span style="color: #990000">:</span>//download<span style="color: #990000">:</span>YOUR_DOWNLOAD_TOKEN@www<span style="color: #990000">.</span>phusionpassenger<span style="color: #990000">.</span>com/enterprise_apt squeeze main</tt></pre>
</div>
</div>
<div class="paragraph"><p>You can find the correct value for <em>YOUR_DOWNLOAD_TOKEN</em> in the <a href="https://www.phusionpassenger.com/orders">Customer Area</a>.</p></div>
</dd>
</dl></div>
</li>
<li>
<p>
Secure <span class="monospaced">passenger.list</span> and update your APT cache:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo chown root: /etc/apt/sources.list.d/passenger.list
sudo chmod 600 /etc/apt/sources.list.d/passenger.list
sudo apt-get update</pre>
</div>
</div>
</li>
</ol></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_installing_packages"></span><h4 data-comment-topic="installing-packages-1jxn722" data-anchor="_installing_packages">2.3.2. Installing packages</h4>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Open source</strong>
</dt>
<dd>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
<a href="#install_add_apt_repo">Add our APT repository.</a>
</p>
</li>
<li>
<p>
Install the package:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo apt-get install libapache2-mod-passenger</pre>
</div>
</div>
</li>
</ol></div>
</dd>
<dt class="hdlist1">
<strong>Enterprise</strong>
</dt>
<dd>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Download your license key from the <a href="https://www.phusionpassenger.com/orders">Customer Area</a> and save it as <span class="monospaced">/etc/passenger-enterprise-license</span>.
</p>
</li>
<li>
<p>
<a href="#install_add_apt_repo">Add our APT repository.</a>
</p>
</li>
<li>
<p>
Install the packages:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo apt-get install libapache2-mod-passenger-enterprise</pre>
</div>
</div>
</li>
</ol></div>
</dd>
</dl></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_installing_or_upgrading_on_red_hat_fedora_centos_or_scientificlinux"></span><h3 data-comment-topic="installing-or-upgrading-on-red-hat-fedora-centos-or-scientificlinux-1y5ie8b" data-anchor="_installing_or_upgrading_on_red_hat_fedora_centos_or_scientificlinux">2.4. Installing or upgrading on Red Hat, Fedora, CentOS or ScientificLinux</h3>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/warning.png" alt="Warning">
</td>
<td class="content">The RPMs are currently unmaintained. As such, the repository only contains Phusion Passenger 3.x (the latest version is 4.x), which did not support Node.js, Meteor, multiple Rubies, etc. For more recent versions of Phusion Passenger, you are suggested to install from gem or tarball instead.</td>
</tr></table>
</div>
<div class="paragraph"><p>YUM repositories with RPMs are maintained by <a href="https://github.com/erikogan/passenger">Erik Ogan</a> and <a href="http://stealthymonkeys.com/">Stealthy Monkeys Consulting</a>. Only packages for the open source version of Phusion Passenger are provided. <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a> customers should use the <a href="#rubygems_generic_install">generic RubyGems installation method</a> or <a href="#tarball_generic_install">the generic tarball installation method</a> instead.</p></div>
<div class="paragraph"><p>If you use YUM to install Phusion Passenger then you do not need to run <span class="monospaced">passenger-install-apache2-module</span> or <span class="monospaced">passenger-install-nginx-module</span>. The YUM packages contain all the binaries that you need. You also don’t need to modify any Apache or Nginx configuration to get them to load Phusion Passenger, the packages provide configuration snippets for you as well.</p></div>
<span class="anchor_helper" id="_step_1_import_the_stealthy_monkeys_consulting_8217_s_gpg_key"></span><h4 class="float" data-anchor="_step_1_import_the_stealthy_monkeys_consulting_8217_s_gpg_key">Step 1: Import the Stealthy Monkeys Consulting’s GPG key</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>rpm --import http://passenger.stealthymonkeys.com/RPM-GPG-KEY-stealthymonkeys.asc</pre>
</div>
</div>
<span class="anchor_helper" id="_step_2_install_the_release_package"></span><h4 class="float" data-anchor="_step_2_install_the_release_package">Step 2: Install the release package</h4>
<div class="paragraph"><p>Install the passenger-release package from the <a href="http://passenger.stealthymonkeys.com/">main repository</a>.</p></div>
<div class="paragraph"><p>Fedora Core 17:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install http://passenger.stealthymonkeys.com/fedora/17/passenger-release.noarch.rpm</pre>
</div>
</div>
<div class="paragraph"><p>Fedora Core 16:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install http://passenger.stealthymonkeys.com/fedora/16/passenger-release.noarch.rpm</pre>
</div>
</div>
<div class="paragraph"><p>Fedora Core 15:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install http://passenger.stealthymonkeys.com/fedora/15/passenger-release.noarch.rpm</pre>
</div>
</div>
<div class="paragraph"><p>Fedora Core 14:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install http://passenger.stealthymonkeys.com/fedora/14/passenger-release.noarch.rpm</pre>
</div>
</div>
<div class="paragraph"><p>RHEL 6 / CentOS 6 / ScientificLinux 6: (Note: these packages depend on <a href="http://fedoraproject.org/wiki/EPEL">EPEL</a>.)</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install http://passenger.stealthymonkeys.com/rhel/6/passenger-release.noarch.rpm</pre>
</div>
</div>
<div class="paragraph"><p>RHEL 5 / CentOS 5 / ScientificLinux 5: (Note: these packages depend on <a href="http://fedoraproject.org/wiki/EPEL">EPEL</a>.)</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>rpm -Uvh http://passenger.stealthymonkeys.com/rhel/5/passenger-release.noarch.rpm</pre>
</div>
</div>
<span class="anchor_helper" id="_step_3_install_the_right_phusion_passenger_package"></span><h4 class="float" data-anchor="_step_3_install_the_right_phusion_passenger_package">Step 3: Install the right Phusion Passenger package</h4>
<div class="paragraph"><p>From there you can use <a href="http://prefetch.net/articles/yum.html">YUM</a> to install packages. For example, try one of these:</p></div>
<div class="paragraph"><p>Phusion Passenger for Apache:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install mod_passenger</pre>
</div>
</div>
<div class="paragraph"><p>Phusion Passenger for Nginx:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install nginx-passenger</pre>
</div>
</div>
<div class="paragraph"><p>Phusion Passenger Standalone:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>yum install passenger-standalone</pre>
</div>
</div>
<span class="anchor_helper" id="_building_your_own_packages"></span><h4 class="float" data-anchor="_building_your_own_packages">Building your own packages</h4>
<div class="paragraph"><p>There are instructions for building your own packages and Yum repositories in the <a href="https://github.com/phusion/passenger/tree/master/rpm#readme">rpm directory ReadMe</a> within the <a href="https://github.com/phusion/passenger">GitHub repository</a>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="rubygems_generic_install"></span><h3 data-comment-topic="installing-via-the-gem-39jw1u" data-anchor="rubygems_generic_install">2.5. Generic installation, upgrade and downgrade method: via RubyGems</h3>
<div class="paragraph"><p>RubyGems is only used as a method to obtain the Phusion Passenger files, so in case you have multiple Ruby versions it does not matter which Ruby’s RubyGems you use for installation. Once installed, Phusion Passenger can work with all other Ruby versions on your system. This is explained in <a href="#relationship_with_ruby">Phusion Passenger and its relationship with Ruby</a>.</p></div>
<span class="anchor_helper" id="is_ruby_home_or_system_wide_installed"></span><h4 class="float" data-anchor="is_ruby_home_or_system_wide_installed">Step 1: figuring out whether your Ruby is installed in the home directory or system-wide</h4>
<div class="paragraph"><p>Ruby may either be installed in the home directory, or system-wide. If it’s installed system-wide then we will want to install gems system-wide as well, so you need to switch to a root prompt first. If Ruby is installed in the home directory then we will want to install gems to the home directory as well, as a normal user.</p></div>
<div class="paragraph"><p>To find out which case applies, run the following command to find out where the <span class="monospaced">ruby</span> command is:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>which ruby</pre>
</div>
</div>
<div class="paragraph"><p>Do you see a filename that references <em>/home</em> or <em>/Users</em>? If so then your Ruby interpreter is installed in your home directory and you can proceed to step 2. Otherwise, you need to switch to a root prompt by running one of the following commands:</p></div>
<div class="ulist"><ul>
<li>
<p>
Are you using RVM? Run <span class="monospaced">rvmsudo -s</span>
</p>
</li>
<li>
<p>
Are you not using RVM, or do you not know what RVM is? Run <span class="monospaced">sudo -s</span>
</p>
</li>
<li>
<p>
Is <em>sudo</em> not installed on your system? Run <span class="monospaced">su -c bash</span>
</p>
</li>
</ul></div>
<div class="paragraph"><p>You must maintain this root prompt throughout this installation guide.</p></div>
<span class="anchor_helper" id="_step_2_install_the_gem"></span><h4 class="float" data-anchor="_step_2_install_the_gem">Step 2: install the gem</h4>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Open Source</strong>
</dt>
<dd>
<p>
Install the latest gem to obtain the files for the latest stable version of the open source Phusion Passenger:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger</pre>
</div>
</div>
<div class="sidebarblock">
<div class="content">
<div class="title">Previous versions and beta versions</div>
<div class="paragraph"><p>Sometimes you will want to obtain the latest beta version of Phusion Passenger. Beta versions are not normally selected by <span class="monospaced">gem install</span>, so to opt-in for beta versions you have to add the <span class="monospaced">--pre</span> argument:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger --pre</pre>
</div>
</div>
<div class="paragraph"><p>If you want to obtain a specific version of Phusion Passenger, e.g. because you are downgrading, then specify the version number with <span class="monospaced">--version</span>:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger --version 3.0.0</pre>
</div>
</div>
<div class="paragraph"><p>If you want to obtain a specific <strong>beta</strong> version of Phusion Passenger then you must also pass <span class="monospaced">--pre</span>:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger --version 3.9.1.beta --pre</pre>
</div>
</div>
</div>
</div>
</dd>
<dt class="hdlist1">
<strong>Enterprise</strong>
</dt>
<dd>
<p>
First, download the <strong>license key</strong> from the <a href="https://www.phusionpassenger.com/orders">Customer Area</a> and save it as <span class="monospaced">/etc/passenger-enterprise-license</span>.
</p>
<div class="paragraph"><p>Next, add the Phusion Passenger Enterprise gem server to your RubyGems source list:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem source --add https://download:YOUR_DOWNLOAD_TOKEN@www.phusionpassenger.com/enterprise_gems/</pre>
</div>
</div>
<div class="paragraph"><p>Substitute <em>YOUR_DOWNLOAD_TOKEN</em> with the one you find in the <a href="https://www.phusionpassenger.com/orders">Customer Area</a>. And notice the <strong>trailing slash</strong> in the URL! It is very important.</p></div>
<div class="paragraph"><p>Finally, install the latest gem to obtain the files for the latest stable version of the open source Phusion Passenger:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger-enterprise-server</pre>
</div>
</div>
<div class="sidebarblock">
<div class="content">
<div class="title">Previous versions and beta versions</div>
<div class="paragraph"><p>Sometimes you will want to obtain the latest beta version of Phusion Passenger Enterprise. Beta versions are not normally selected by <span class="monospaced">gem install</span>, so to opt-in for beta versions you have to add the <span class="monospaced">--pre</span> argument:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger-enterprise-server --pre</pre>
</div>
</div>
<div class="paragraph"><p>If you want to obtain a specific version of Phusion Passenger Enterprise, e.g. because you are downgrading, then specify the version number with <span class="monospaced">--version</span>:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger-enterprise-server --version 3.0.0</pre>
</div>
</div>
<div class="paragraph"><p>If you want to obtain a specific <strong>beta</strong> version of Phusion Passenger then you must also pass <span class="monospaced">--pre</span>:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install passenger-enterprise-server --version 3.9.1.beta --pre</pre>
</div>
</div>
</div>
</div>
</dd>
</dl></div>
<span class="anchor_helper" id="run_passenger_installer"></span><h4 class="float" data-anchor="run_passenger_installer">Step 3: run the Phusion Passenger installer</h4>
<div class="paragraph"><p>The Phusion Passenger gem only contains source files. In this step we will use the installer to compile the Phusion Passenger binaries, which include the various Phusion Passenger agent executables and the Apache module.</p></div>
<div class="paragraph"><p>Run the following command and follow the on-screen instructions.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>passenger-install-apache2-module</pre>
</div>
</div>
<div class="paragraph"><p>At the end of the installation process, you will be asked to copy and paste a configuration snippet (containing <span class="monospaced">LoadModule</span>, <span class="monospaced">PassengerRoot</span>, etc.) into your Apache configuration file. If you’re upgrading, then you already had a similar configuration snippet. Be sure to remove the old one before pasting the new one.</p></div>
<div class="paragraph"><p>Different operating systems and Apache installations have different conventions with regard to where the Apache configuration file is and how it is organized. Please read <a href="#working_with_apache_conf">Working with the Apache configuration file</a> if you’re not familiar with it. That section is especially of interest for OS X Server >= 10.8 users because the configuration file may not be at a surprising location.</p></div>
<div class="paragraph"><p>If compilation doesn’t succeed, then please consult the <a href="#troubleshooting">Troubleshooting</a> section.</p></div>
<div class="paragraph">
<div class="title">What does the installer do?</div>
<p>Despite the name, this "installer" doesn’t actually install anything. The installer checks whether all required dependencies are installed, invokes the compiler, and tells you how to modify the Apache
configuration file. However, it doesn’t copy any files to outside the Phusion Passenger source directory.</p>
</div>
<div class="paragraph"><p><span class="monospaced">passenger-install-apache2-module</span> is actually just a user-friendly frontend around the command <span class="monospaced">rake apache2</span>, which performs the actual compilation of Phusion Passenger.</p></div>
<span class="anchor_helper" id="_step_4_restarting_the_flying_passenger_daemon"></span><h4 class="float" data-anchor="_step_4_restarting_the_flying_passenger_daemon">Step 4: restarting the Flying Passenger daemon</h4>
<div class="paragraph"><p>If you are using <a href="#flying_passenger">Flying Passenger</a> then you must restart the Flying Passenger daemon by sending it the SIGTERM signal:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>kill `cat /path-to/flying-passenger.pid`</pre>
</div>
</div>
<div class="paragraph"><p>Or, if Flying Passenger is not running with a PID file, look up its PID us <span class="monospaced">ps</span> and then send it SIGTERM:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>ps aux | grep flying-passenger
kill PID_OF_FLYING_PASSENGER</pre>
</div>
</div>
<span class="anchor_helper" id="verify_passenger_running"></span><h4 class="float" data-anchor="verify_passenger_running">Step 5: verifying that Phusion Passenger is running</h4>
<div class="paragraph"><p>Restart your web server and run:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>passenger-memory-stats</pre>
</div>
</div>
<div class="paragraph"><p>You should see the web server processes as well as a number of Phusion Passenger processes (e.g. PassengerWatchdog, PassengerHelperAgent). Congratulations, Phusion Passenger is now installed and running!</p></div>
<div class="paragraph"><p>If the output is not as expected, then please refer to the <a href="#troubleshooting">Troubleshooting</a> section.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="tarball_generic_install"></span><h3 data-comment-topic="installing-via-the-source-tarball-1cgxrqc" data-anchor="tarball_generic_install">2.6. Generic installation, upgrade and downgrade method: via tarball</h3>
<span class="anchor_helper" id="_step_1_installing_ruby"></span><h4 class="float" data-anchor="_step_1_installing_ruby">Step 1: installing Ruby</h4>
<div class="paragraph"><p>Phusion Passenger supports multiple languages and its core is written in C++, but its installer and administration tools are written in Ruby, so you must install Ruby.</p></div>
<div class="paragraph"><p>Even though Ruby is required, Ruby will normally not be loaded during normal operation unless you deploy a Ruby web application on Phusion Passenger. Phusion Passenger’s dependency on Ruby is very minimal. See <a href="#relationship_with_ruby">Phusion Passenger and its relationship with Ruby</a> for details.</p></div>
<table class="tableblock frame-all grid-all" style="
width:100%;
">
<col style="width:50%;">
<col style="width:50%;">
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Debian, Ubuntu</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><span class="monospaced">sudo apt-get update</span><br>
<span class="monospaced">sudo apt-get install ruby rake</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Red Hat, CentOS, ScientificLinux, Amazon Linux</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Enable <a href="http://fedoraproject.org/wiki/EPEL">EPEL</a>, then run as root:<br>
<span class="monospaced">yum install ruby rubygem-rake</span></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Mac OS X</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">No action needed. Ruby is installed by default.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Other operating systems</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Install Ruby from <a href="http://www.ruby-lang.org/">the Ruby website</a>.</p></td>
</tr>
</tbody>
</table>
<span class="anchor_helper" id="_step_2_download_and_extract_the_tarball"></span><h4 class="float" data-anchor="_step_2_download_and_extract_the_tarball">Step 2: download and extract the tarball</h4>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Open Source</strong>
</dt>
<dd>
<p>
Download the open source Phusion Passenger tarball from <a href="https://www.phusionpassenger.com/download#open_source">the Phusion Passenger website</a>.
</p>
<div class="paragraph"><p>Older versions can be found in <a href="https://www.phusionpassenger.com/file_releases">the release archive</a>.</p></div>
</dd>
<dt class="hdlist1">
<strong>Enterprise</strong>
</dt>
<dd>
<p>
<a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a> customers can download the Phusion Passenger Enterprise tarball from the <a href="https://www.phusionpassenger.com/orders">Customer Area</a>.
</p>
<div class="paragraph"><p>Also be sure to download the <strong>license key</strong> and save it as <span class="monospaced">/etc/passenger-enterprise-license</span>.</p></div>
</dd>
</dl></div>
<div class="paragraph"><p>Once you have downloaded the tarball, pick a location to extract it to. You can pick any location. A good location is <em>/opt/passenger</em>. Create this directory and extract the tarball as follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>mkdir /opt/passenger
cd /opt/passenger
tar xzvf /location-to/passenger-x.x.x.tar.gz
cd /opt/passenger/passenger-x.x.x</pre>
</div>
</div>
<div class="paragraph"><p>Note that <span class="monospaced">passenger-x.x.x</span> should be <span class="monospaced">passenger-enterprise-server-x.x.x</span> if you’re using Phusion Passenger Enterprise.</p></div>
<span class="anchor_helper" id="_step_3_run_the_phusion_passenger_installer"></span><h4 class="float" data-anchor="_step_3_run_the_phusion_passenger_installer">Step 3: run the Phusion Passenger installer</h4>
<div class="paragraph"><p>The Phusion Passenger gem only contains source files. In this step we will use the installer to compile the Phusion Passenger binaries, which include the various Phusion Passenger agent executables and the Apache module.</p></div>
<div class="paragraph"><p>Run the following command and follow the on-screen instructions.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>./bin/passenger-install-apache2-module</pre>
</div>
</div>
<div class="paragraph"><p>At the end of the installation process, you will be asked to copy and paste a configuration snippet (containing <span class="monospaced">LoadModule</span>, <span class="monospaced">PassengerRoot</span>, etc.) into your Apache configuration file. If you’re upgrading, then you already had a similar configuration snippet. Be sure to remove the old one before pasting the new one.</p></div>
<div class="paragraph"><p>Different operating systems and Apache installations have different conventions with regard to where the Apache configuration file is and how it is organized. Please read <a href="#working_with_apache_conf">Working with the Apache configuration file</a> if you’re not familiar with it. That section is especially of interest for OS X Server >= 10.8 users because the configuration file may not be at a surprising location.</p></div>
<div class="paragraph"><p>If compilation doesn’t succeed, then please consult the <a href="#troubleshooting">Troubleshooting</a> section.</p></div>
<div class="paragraph">
<div class="title">What does the installer do?</div>
<p>Despite the name, this "installer" doesn’t actually install anything. The installer checks whether all required dependencies are installed, invokes the compiler, and tells you how to modify the Apache
configuration file. However, it doesn’t copy any files to outside the Phusion Passenger source directory.</p>
</div>
<div class="paragraph"><p><span class="monospaced">passenger-install-apache2-module</span> is actually just a user-friendly frontend around the command <span class="monospaced">rake apache2</span>, which performs the actual compilation of Phusion Passenger.</p></div>
<span class="anchor_helper" id="_step_4_verifying_that_phusion_passenger_is_running"></span><h4 class="float" data-anchor="_step_4_verifying_that_phusion_passenger_is_running">Step 4: verifying that Phusion Passenger is running</h4>
<div class="paragraph"><p>Restart your web server and run:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>./bin/passenger-memory-stats</pre>
</div>
</div>
<div class="paragraph"><p>You should see the web server processes as well as a number of Phusion Passenger processes (e.g. PassengerWatchdog, PassengerHelperAgent). Congratulations, Phusion Passenger is now installed and running!</p></div>
<div class="paragraph"><p>If the output is not as expected, then please refer to the <a href="#troubleshooting">Troubleshooting</a> section.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_upgrading_from_open_source_to_enterprise"></span><h3 data-comment-topic="upgrading-from-open-source-to-enterprise-b17h8g" data-anchor="_upgrading_from_open_source_to_enterprise">2.7. Upgrading from open source to Enterprise</h3>
<div class="paragraph"><p>Phusion Passenger comes in two variants: an open source version, as well as an <a href="https://www.phusionpassenger.com/enterprise">Enterprise version</a> which introduces a myriad of useful features that can improve stability and performance and efficiency.</p></div>
<div class="paragraph"><p>Customers who have bought Phusion Passenger Enterprise can upgrade their open source installation to Enterprise as follows:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
<a href="#uninstalling">Uninstall the open source Phusion Passenger</a>.
</p>
</li>
<li>
<p>
Install the Enterprise version by following one of the installation guides in this section (e.g. <a href="#rubygems_generic_install">RubyGems generic installation</a> or <a href="#tarball_generic_install">tarball generic installation</a>).
</p>
</li>
</ol></div>
<div class="paragraph"><p>The uninstallation is necessary because the Enterprise Ruby gem has a different gem name (<em>passenger-enterprise-server</em> instead of <em>passenger</em>), but the same administration command names (e.g. <span class="monospaced">passenger-status</span>). Uninstalling the open source version avoids any conflicts.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_cryptographic_verification_of_installation_files"></span><h3 data-comment-topic="cryptographic-verification-of-installation-files-ed3r9v" data-anchor="_cryptographic_verification_of_installation_files">2.8. Cryptographic verification of installation files</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_synopsis_2"></span><h4 data-comment-topic="synopsis-uwnz2o" data-anchor="_synopsis_2">2.8.1. Synopsis</h4>
<div class="paragraph"><p>We digitally sign various files with our GPG key so that you can check whether they’re legit, i.e. whether they really came from Phusion and haven’t been tampered with by a third party. We apply signing since the open source version 4.0.0 RC 4, or the Enterprise version 4.0.0 RC 1.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_importing_the_phusion_software_signing_key"></span><h4 data-comment-topic="importing-the-phusion-software-signing-key-1x0rhv" data-anchor="_importing_the_phusion_software_signing_key">2.8.2. Importing the Phusion Software Signing key</h4>
<div class="paragraph"><p>Phusion’s GPG key for signing software is as follows:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>Phusion Software Signing (software-signing@phusion.nl)
Short key ID: 0x0A212A8C
Long key ID: 0x2AC745A50A212A8C
Fingerprint: D5F0 8514 2693 9232 F437 AB72 2AC7 45A5 0A21 2A8C</pre>
</div>
</div>
<div class="paragraph"><p>This key is stored at <a href="http://www.phusion.nl/about/gpg">the Phusion website</a> and at the key servers <a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x2AC745A50A212A8C">sks-keyservers.net</a> and <a href="http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2AC745A50A212A8C">keyserver.ubuntu.com</a>. You can import it to your keyring with one of these command:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gpg --keyserver pool.sks-keyservers.net --search-keys 0x2AC745A50A212A8C
# -OR-
gpg --keyserver keyserver.ubuntu.com --search-keys 0x2AC745A50A212A8C</pre>
</div>
</div>
<div class="paragraph"><p>The Phusion Software Signing key is only used for signing software. It’s never used for signing emails or for encrypting files, so please be suspicious if you encounter usage of this key outside the context of signing software, and alert us at <a href="mailto:support@phusion.nl">support@phusion.nl</a>. Include "notspam" in the message to bypass our spam filter.</p></div>
<div class="paragraph"><p>The email address <a href="mailto:software-signing@phusion.nl">software-signing@phusion.nl</a> redirects to <a href="mailto:info@phusion.nl">info@phusion.nl</a> so it’s safe to send email there.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_verifying_the_phusion_software_signing_key"></span><h4 data-comment-topic="verifying-the-phusion-software-signing-key-10430lg" data-anchor="_verifying_the_phusion_software_signing_key">2.8.3. Verifying the Phusion Software Signing key</h4>
<div class="paragraph"><p>The Phusion Software Signing key is also <strong>signed by the Phusion founders</strong>. Their keys are as follows:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>Hongli Lai (hongli@phusion.nl)
Short key ID: 4B6F4332
Long key ID: 06A131094B6F4332
Fingerprint: 64E8 0420 FC6A 499F 9E1F 81FA 06A1 3109 4B6F 4332</pre>
</div>
</div>
<div class="literalblock">
<div class="content monospaced">
<pre>Ninh Bui (ninh@phusion.nl)
Short key ID: 6FAF3782
Long key ID: BA8DA3F46FAF3782
Fingerprint: 353A 398C 49AF 5CD5 74A0 656C BA8D A3F4 6FAF 3782</pre>
</div>
</div>
<div class="paragraph"><p>Both keys are stored at both sks-servers.net and keyserver.ubuntu.com. Import them with:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gpg --keyserver pool.sks-servers.net --search-keys 0x06A131094B6F4332
gpg --keyserver pool.sks-servers.net --search-keys 0xBA8DA3F46FAF3782
# -OR-
gpg --keyserver keyserver.ubuntu.com --search-keys 0x06A131094B6F4332
gpg --keyserver keyserver.ubuntu.com --search-keys 0xBA8DA3F46FAF3782</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_verifying_the_gem_and_tarball"></span><h4 data-comment-topic="verifying-the-gem-and-tarball-1nf0uov" data-anchor="_verifying_the_gem_and_tarball">2.8.4. Verifying the gem and tarball</h4>
<div class="paragraph"><p>You can find the open source version’s gem and tarball GPG signatures at <a href="https://www.phusionpassenger.com/file_releases">https://www.phusionpassenger.com/file_releases</a>. The Enterprise version’s GPG signatures can be found in the <a href="https://www.phusionpassenger.com/orders">Customer Area</a>. All signatures have the <em>.asc</em> extension. Once you have imported our key, you can verify the validity of a file against its signature as follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ gpg --verify passenger-x.x.x.tar.gz.asc passenger-x.x.x.tar.gz
gpg: Signature made Mon Mar 11 09:45:46 2013 CET using RSA key ID 0A212A8C
gpg: Good signature from "Phusion Software Signing <software-signing@phusion.nl>"</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_verifying_git_signatures"></span><h4 data-comment-topic="verifying-git-signatures-oaafwd" data-anchor="_verifying_git_signatures">2.8.5. Verifying Git signatures</h4>
<div class="paragraph"><p>Tags in the <a href="https://github.com/phusion/passenger">Git repository for the open source version</a> are also tagged. You can verify a Git tag as follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ git tag --verify release-x.x.x
object d886f34b5705e4314feccaf0d77b9a38416e15e0
type commit
tag release-4.0.0.rc5
tagger Hongli Lai (Phusion) <hongli@phusion.nl> 1362993117 +0100
This is a tag message.
gpg: Signature made Mon Mar 11 10:12:02 2013 CET using RSA key ID 0A212A8C
gpg: Good signature from "Phusion Software Signing <software-signing@phusion.nl>"</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_verifying_deb_and_rpm_packages"></span><h4 data-comment-topic="verifying-deb-and-rpm-packages-vgtv04" data-anchor="_verifying_deb_and_rpm_packages">2.8.6. Verifying DEB and RPM packages</h4>
<div class="paragraph"><p>The DEB and RPM packages are signed with the signatures of the respective packagers. They are automatically checked upon installation.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_revocation"></span><h4 data-comment-topic="revocation-4o01n2" data-anchor="_revocation">2.8.7. Revocation</h4>
<div class="paragraph"><p>In the event our key is compromised, we will revoke the key and upload the revocation information to sks-servers.net and keyserver.ubuntu.com. However your system will not know about the revocation until you update the keys from the keyservers. You should update your keys regularly (e.g. once a week) by invoking:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gpg --refresh-keys --keyserver pool.sks-servers.net
# -OR-
gpg --refresh-keys --keyserver keyserver.ubuntu.com</pre>
</div>
</div>
<div class="paragraph"><p>If you installed Phusion Passenger through our APT repository, then you should update APT’s keyring from time to time as well:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_non_interactive_automatic_headless_installs_or_upgrades"></span><h3 data-comment-topic="non-interactive-automatic-headless-installs-or-upgrades-1arnxii" data-anchor="_non_interactive_automatic_headless_installs_or_upgrades">2.9. Non-interactive, automatic, headless installs or upgrades</h3>
<div class="paragraph"><p>By default, the installer (<span class="monospaced">passenger-install-apache2-module</span>) is interactive. If you want to automate installation then you can do so by passing <span class="monospaced">--auto</span> to the installer. See also <span class="monospaced">passenger-install-apache2-module --help</span> for more options.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_customizing_the_compilation_process"></span><h3 data-comment-topic="customizing-the-compilation-process-1sds3od" data-anchor="_customizing_the_compilation_process">2.10. Customizing the compilation process</h3>
<div class="paragraph"><p>The Phusion Passenger compilation process can be customized with environment variables. You can learn more about environment variables in <a href="#about_environment_variables">About environment variables</a>.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_setting_the_compiler"></span><h4 data-comment-topic="setting-the-compiler-1symq7h" data-anchor="_setting_the_compiler">2.10.1. Setting the compiler</h4>
<div class="paragraph"><p>You can force the Phusion Passenger build system to use a specific C or C++ compiler by setting the <span class="monospaced">CC</span> and <span class="monospaced">CXX</span> environment variables. These may be set to any arbitrary shell commands.</p></div>
<div class="paragraph"><p>For example, contributors who want to hack on Phusion Passenger may want to use Clang for faster compilation and <a href="http://ccache.samba.org/">ccache</a> for faster recompilation, and may want to enable more error-catching compilation flags:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">CC</span><span style="color: #990000">=</span><span style="color: #FF0000">'ccache clang -fcolor-diagnostics -Qunused-arguments -fcatch-undefined-behavior -ftrapv'</span>
<span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">CXX</span><span style="color: #990000">=</span><span style="color: #FF0000">'ccache clang++ -fcolor-diagnostics -Qunused-arguments -fcatch-undefined-behavior -ftrapv'</span></tt></pre>
</div>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">If you run the installer with <span class="monospaced">sudo</span> then environment variables may not be passed properly. Learn more at <a href="#env_vars_and_sudo">Environment variables and sudo</a>.</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_adding_additional_compiler_or_linker_flags"></span><h4 data-comment-topic="adding-additional-compiler-or-linker-flags-wzu0ey" data-anchor="_adding_additional_compiler_or_linker_flags">2.10.2. Adding additional compiler or linker flags</h4>
<div class="paragraph"><p>On some systems, C/C++ libraries and headers that Phusion Passenger requires may be located in a non-standard directory. You can force the Phusion Passenger build system to look in those locations by injecting compiler and linker flags using the following environment variables:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<span class="monospaced">EXTRA_PRE_CFLAGS</span>
</dt>
<dd>
<p>
These flags are injected into all C compiler invocations that involve compiling C source files. This also covers compiler invocations that compile <strong>and</strong> link. The flags are injected at the beginning of the command string, even before <span class="monospaced">EXTRA_PRE_LDFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_CFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_PRE_CFLAGS</span>, but injected at the end of the command string, before <span class="monospaced">EXTRA_LDFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_PRE_CXXFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_PRE_CFLAGS</span>, but for C++ compiler invocations.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_CXXFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_CFLAGS</span>, but for C++ compiler invocations.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_PRE_LDFLAGS</span>
</dt>
<dd>
<p>
These flags are injected into all C/C++ compiler invocations that involve linking. This includes compiler invocations that compile <strong>and</strong> link. The flags are injected at the beginning of the command string, but after <span class="monospaced">EXTRA_PRE_CFLAGS</span>/<span class="monospaced">EXTRA_PRE_CXXFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_PRE_C_LDFLAGS</span>
</dt>
<dd>
<p>
These flags are injected into all C compiler invocations that involve linking, right after <span class="monospaced">EXTRA_PRE_LDFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_PRE_CXX_LDFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_PRE_CXX_LDFLAGS</span>, but for C++ compiler invocations.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_LDFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_PRE_LDFLAGS</span>, but injected at the very end of the command string, even after <span class="monospaced">EXTRA_CFLAGS</span> and <span class="monospaced">EXTRA_CXXFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_C_LDFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_LDFLAGS</span>, but only injected for C executable linking commands. Injected right after <span class="monospaced">EXTRA_LDFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">EXTRA_CXX_LDFLAGS</span>
</dt>
<dd>
<p>
Similar to <span class="monospaced">EXTRA_LDFLAGS</span>, but only injected for C++ executable linking commands. Injected right after <span class="monospaced">EXTRA_LDFLAGS</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">PASSENGER_THREAD_LOCAL_STORAGE</span>
</dt>
<dd>
<p>
Setting this to 1 will enable the <span class="monospaced">PASSENGER_THREAD_LOCAL_STORAGE</span> macro, which forcefully disables the use of thread-local storage inside the Phusion Passenger codebase. Setting this environment variable is useful on systems that have broken support for thread-local storage, despite passing our build system’s check for proper thread-local storage support. At the time of writing, one user has reported that Ubuntu 12.04 32-bit has broken thread-local storage report although neither the reporter nor us were able to reproduce the problem on any other systems running Ubuntu 12.04 32-bit. Note that this flag has no effect on non-Phusion Passenger code.
</p>
</dd>
</dl></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">If you run the installer with <span class="monospaced">sudo</span> then environment variables may not be passed properly. Learn more at <a href="#env_vars_and_sudo">Environment variables and sudo</a>.</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="forcing_location_of_command_line_tools_and_dependencies"></span><h4 data-comment-topic="forcing-location-of-certain-command-line-tools-1hym30u" data-anchor="forcing_location_of_command_line_tools_and_dependencies">2.10.3. Forcing location of command line tools and dependencies</h4>
<div class="paragraph"><p>The Phusion Passenger build system attempts to autodetect many things by locating relevant helper tools. For example, to find out which compiler flags it should use for compiling Apache modules, it locates the <span class="monospaced">apxs2</span> command and queries it. To find out which compiler flags it should use for libcurl, it queries the <span class="monospaced">curl-config</span> command. These commands may not be in <span class="monospaced">$PATH</span>, or even when they are you may want to use a different one.</p></div>
<div class="paragraph"><p>You can force the build to find certain command line tools at certain locations by using the following environment variables:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<span class="monospaced">HTTPD</span>
</dt>
<dd>
<p>
The location of the <span class="monospaced">httpd</span> executable (the Apache server executable).
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">APXS2</span>
</dt>
<dd>
<p>
The location of the <span class="monospaced">apxs2</span> executable (the Apache module developer tool). Only used by <span class="monospaced">passenger-install-apache2-module</span>.
</p>
<div class="paragraph"><p>This environment variable, together with <span class="monospaced">HTTPD</span>, are what you need to customize if you have multiple Apache installations on your system, or if your Apache is located in a non-standard location which Phusion Passenger cannot detect. By setting <span class="monospaced">APXS2</span> and <span class="monospaced">HTTP</span> to the right paths, you can force Phusion Passenger to be compiled against that specific Apache installation.</p></div>
<div class="paragraph"><p>For example, if your Apache installation is located in <span class="monospaced">/opt/lamp/apache2</span>, then you can run the installer as follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo bash
# export HTTPD=/opt/lampp/apache2/bin/apache
# export APXS2=/opt/lampp/apache2/bin/apxs
# passenger-install-apache2-module</pre>
</div>
</div>
</dd>
<dt class="hdlist1">
<span class="monospaced">APR_CONFIG</span>
</dt>
<dd>
<p>
The location of the <span class="monospaced">apr-config</span> executable (the Apache Portable Runtime developer tool).
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">APU_CONFIG</span>
</dt>
<dd>
<p>
The location of the <span class="monospaced">apu-config</span> executable (the Apache Portable Runtime Utility developer tool).
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">MAKE</span>
</dt>
<dd>
<p>
The location of a <span class="monospaced">make</span> tool. It does not matter which implementation of <span class="monospaced">make</span> this is.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">GMAKE</span>
</dt>
<dd>
<p>
The location of the GNU-compatible <span class="monospaced">make</span> tool.
</p>
</dd>
</dl></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip">
</td>
<td class="content">If you do not know what environment variables are, or how to use them, then please read <a href="#env_vars_and_sudo">Environment variables and sudo</a>.</td>
</tr></table>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">If you run the installer with <span class="monospaced">sudo</span> then environment variables may not be passed properly. Learn more at <a href="#env_vars_and_sudo">Environment variables and sudo</a>.</td>
</tr></table>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="multiple_apache_installs"></span><h3 data-comment-topic="dealing-with-multiple-apache-installations-ks5nkz" data-anchor="multiple_apache_installs">2.11. Dealing with multiple Apache installations</h3>
<div class="paragraph"><p>Some systems have multiple Apache installations. Maybe you already know about that, and you installed multiple Apaches for a reason. Or maybe you did so in the past but then forgot about the other installs. Or maybe someone else — or some other software — installed another Apache for you without your knowledge.</p></div>
<div class="paragraph"><p>Whatever the reason might be, it is important that you know about the existance of multiple Apache installations, and that you decide <strong>which one</strong> you want to use. <strong>Unless you know exactly what you are doing, we recommend that you remove all the Apache installations that you don’t intend to use, in order to avoid confusion and problems</strong>. You should end up with only a single Apache installation. Unfortunately, this manual cannot tell you how to remove the other Apache installs: it depends on how you originally installed them. Usually it’s a matter of removing the directories that they’re located in, and removing their configuration files. But some Apache distributions might bundle an uninstaller. You need to do the proper research on how they ended up there in the first place.</p></div>
<div class="paragraph"><p>Phusion Passenger provides a tool to check whether you have multiple Apache installations on your system. You can invoke the tool by running <span class="monospaced">passenger-config --detect-apache2</span>.</p></div>
<div class="paragraph"><p>If the existance of multiple Apache installations is intentional, then Phusion Passenger can happily go along with your choice: you simply have to tell <span class="monospaced">passenger-install-apache2-module</span> which Apache to install against. There are several ways to specify which Apache you want to install against:</p></div>
<div class="ulist"><ul>
<li>
<p>
By passing the <span class="monospaced">--apxs2-path</span> parameter. The <span class="monospaced">passenger-config --detect-apache2</span> command will tell you how to use this parameter.
</p>
</li>
<li>
<p>
By setting <span class="monospaced">APXS2</span>, <span class="monospaced">HTTPD</span> and other kinds of environment variables. Please refer to <a href="#forcing_location_of_command_line_tools_and_dependencies">Forcing location of command line tools and dependencies</a> for more information.
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="working_with_apache_conf"></span><h3 data-comment-topic="locating-the-apache-configuration-file-1fterqv" data-anchor="working_with_apache_conf">2.12. Working with the Apache configuration file</h3>
<div class="paragraph"><p>On most systems the Apache configuration file is located in either <em>/etc/apache2/httpd.conf</em> or <em>/etc/apache2/apache2.conf</em>. However, to allow better organization, many operating systems and Apache distributions also read configuration files in the <em>conf.d</em>, <em>mods-enabled</em> and <em>sites-enabled</em> subdirectories.</p></div>
<div class="paragraph"><p><em>mods-enabled</em> contains symlinks to files in <em>mods-available</em>. This latter subdirectory contains config files for all available modules, while <em>mods-enabled</em> contains only a subset, namely the modules that should actually be enabled. The symlinks are created using the <span class="monospaced">a2enmod</span> tool. <em><strong>.load</strong></em> files contain <span class="monospaced">LoadModule</span> directives, while <em>.conf</em> files contain all other configuration directives.</p></div>
<div class="paragraph"><p>Use <em>mods-enabled</em>/<em>mods-available</em> to store Phusion Passenger configuration if you can:</p></div>
<div class="ulist"><ul>
<li>
<p>
Create <em>/etc/apache2/mods-available/passenger.load</em> and paste the <span class="monospaced">LoadModule ...</span> directive that <span class="monospaced">passenger-install-apache2-module</span> outputs.
</p>
</li>
<li>
<p>
Create <em>/etc/apache2/mods-available/passenger.conf</em> and paste the <span class="monospaced">PassengerRoot</span> and other Phusion Passenger options.
</p>
</li>
<li>
<p>
Enable by running <span class="monospaced">sudo a2enmod passenger</span>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>If the <em>mods-enabled</em> mechanism is not available then you can paste configuration snippets into <em>httpd.conf</em> or <em>apache2.conf</em> directly.</p></div>
<div class="paragraph"><p>On OS X Server >= 10.8 Mountain Lion the location of the Apache configuration file depends on whether you use Web Services or not. If you do, then the configuration file is in <em>/Library/Server/Web/Config/apache2/httpd_server_app.conf</em>. If you do not, then the configuration file is in <em>/etc/apache2/httpd.conf</em>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_disabling_without_uninstalling"></span><h3 data-comment-topic="unloading-disabling-phusion-passenger-from-apache-without-uninstalling-it-s1axnx" data-anchor="_disabling_without_uninstalling">2.13. Disabling without uninstalling</h3>
<div class="paragraph"><p>You can temporarily unload (disable) Phusion Passenger from the web server, without
uninstalling the Phusion Passenger files, so that the web server behaves as if Phusion
Passenger was never installed in the first place. This might be useful to you if -
for example - you seem to be experiencing a problem caused by Phusion Passenger,
but you want to make sure whether that’s actually the case without having
to go through the hassle of uninstalling Phusion Passenger completely. When disabled,
Phusion Passenger will not occupy any memory or CPU or otherwise interfere with
the web server.</p></div>
<div class="paragraph"><p>To unload Phusion Passenger from the web server, edit your Apache configuration file(s)
and comment out:</p></div>
<div class="ulist"><ul>
<li>
<p>
all Phusion Passenger configuration directives.
</p>
</li>
<li>
<p>
the <span class="monospaced">LoadModule passenger_module</span> directive.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example, if your configuration file looks like this…</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Listen *:80
NameVirtualHosts *:80
....
LoadModule passenger_module /somewhere/passenger-x.x.x/ext/apache2/mod_passenger.so
PassengerRoot /somewhere/passenger/x.x.x
PassengerDefaultRuby /usr/bin/ruby
PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /webapps/foo/public
RailsBaseURI /rails
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>…then comment out the relevant directives, so that it looks like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Listen *:80
NameVirtualHosts *:80
....
# LoadModule passenger_module /somewhere/passenger-x.x.x/ext/apache2/mod_passenger.so
# PassengerRoot /somewhere/passenger/x.x.x
# PassengerDefaultRuby /usr/bin/ruby
# PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /webapps/foo/public
# RailsBaseURI /rails
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>After you’ve done this, save the configuration file and restart the web server.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="uninstalling"></span><h3 data-comment-topic="uninstalling-phusion-passenger-1qb4ssq" data-anchor="uninstalling">2.14. Uninstalling</h3>
<div class="paragraph"><p>To uninstall Phusion Passenger, please first remove all Phusion Passenger
configuration directives from your web server configuration file(s). After you’ve
done this, you need to remove the Phusion Passenger files.</p></div>
<div class="ulist"><ul>
<li>
<p>
If you installed Phusion Passenger via a Ruby gem, then run <span class="monospaced">gem uninstall passenger</span> (or, if you’re a <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a> user, <span class="monospaced">gem uninstall passenger-enterprise-server</span>).
You <a href="#is_ruby_home_or_system_wide_installed">might have to run this as root</a>.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger via a source tarball, then remove the directory
in which you placed the extracted Phusion Passenger files. This directory is the
same as the one pointed to the by <span class="monospaced">PassengerRoot</span>/<span class="monospaced">passenger_root</span> configuration directive.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger through APT or YUM, then use them to uninstall Phusion Passenger.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger through Homebrew, then run <span class="monospaced">brew uninstall passenger</span>.
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="moving_phusion_passenger"></span><h3 data-comment-topic="moving-to-a-different-directory-1n0gkwh" data-anchor="moving_phusion_passenger">2.15. Moving to a different directory</h3>
<div class="paragraph"><p>If you installed Phusion Passenger through a tarball then you can move the Phusion Passenger directory to another location. This is not possible if you used any of the other installation methods.</p></div>
<div class="paragraph"><p>First, move the directory to whereever you like:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>mv /opt/passenger/passenger-4.0.0 /usr/local/passenger-4.0.0</pre>
</div>
</div>
<div class="paragraph"><p>Next you must tell Apache that Phusion Passenger has moved.
Open your <a href="#working_with_apache_conf">Apache configuration file</a> and set the <em>PassengerRoot</em> directive to the new location:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>PassengerRoot /usr/local/passenger-4.0.0</pre>
</div>
</div>
<div class="paragraph"><p>Restart your web server to finalize the change.</p></div>
<div class="paragraph"><p>If you used <a href="#tarball_generic_install">the tarball installation method</a> and you added Phusion Passenger’s <span class="monospaced">bin</span> subdirectory to <span class="monospaced">PATH</span>, then you must update your PATH with the new location. Open <span class="monospaced">/etc/bashrc</span> (or <span class="monospaced">/etc/bash.bashrc</span> on some systems) and change:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>export PATH=/opt/passenger/passenger-4.0.0/bin:$PATH</pre>
</div>
</div>
<div class="paragraph"><p>to:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>export PATH=/usr/local/passenger-4.0.0/bin:$PATH</pre>
</div>
</div>
<div class="paragraph"><p>Finally, restart all your shell sessions to activate the PATH change.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_a_ruby_on_rails_1_x_or_2_x_but_not_rails_gt_3_x_application"></span><h2 data-comment-topic="deploying-a-ruby-on-rails-1-x-or-2-x-but-not-rails-3-x-application-9r92hi" data-anchor="_deploying_a_ruby_on_rails_1_x_or_2_x_but_not_rails_gt_3_x_application">3. Deploying a Ruby on Rails 1.x or 2.x (but NOT Rails >= 3.x) application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Suppose you have a Ruby on Rails application in <em>/webapps/mycook</em>, and you own
the domain <em>www.mycook.com</em>. You can either deploy your application to the
virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.mycook.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.mycook.com/railsapplication</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">The default <span class="monospaced">RAILS_ENV</span> environment in which deployed Rails applications
are run, is “production”. You can change this by changing the
<a href="#rails_env"><em>RailsEnv</em></a> configuration option.</td>
</tr></table>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_to_a_virtual_host_8217_s_root"></span><h3 data-comment-topic="deploying-to-a-virtual-host-s-root-ab4zj6" data-anchor="_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host’s root</h3>
<div class="paragraph"><p>Add a virtual host entry to your Apache configuration file. Make sure that the
following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
The virtual host’s document root must point to your Ruby on Rails application’s
<em>public</em> folder.
</p>
</li>
<li>
<p>
The Apache per-directory permissions must allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews must be disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.mycook.com
DocumentRoot /webapps/mycook/public
<Directory /webapps/mycook/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>You may also need to tweak your file/folder permissions. Make sure that the
following folders are readable and executable by Apache:</p></div>
<div class="ulist"><ul>
<li>
<p>
this <em>public</em> folder.
</p>
</li>
<li>
<p>
the application’s <em>config</em> folder.
</p>
</li>
<li>
<p>
all parent folders. That is, /webapps/mycook and /webapps must also be readable and executable by Apache.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="deploying_rails_to_sub_uri"></span><h3 data-comment-topic="deploying-to-a-sub-uri-13rfygg" data-anchor="deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</h3>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>And you want your Rails application, located in <span class="monospaced">/websites/rails</span>, to be accessible from the URL
<em>http://www.phusion.nl/subapp</em>.</p></div>
<div class="paragraph"><p>To do this, you need to perform the following:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Set <span class="monospaced">Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Location /{SUBURI}></span> block.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerBaseURI /{SUBURI}</span>.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}></span> block.
</p>
</li>
<li>
<p>
Inside the Directory block, set <span class="monospaced">Allow from all</span>.
</p>
</li>
<li>
<p>
Inside the Directory block, disable MultiViews.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Here is an example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
# These have been added:
Alias /subapp /websites/rails/public
<Location /subapp>
PassengerBaseURI /subapp
PassengerAppRoot /websites/rails
</Location>
<Directory /websites/rails/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed to the sub-URI.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">If you’re deploying to a sub-URI then please make sure that your view
templates correctly handles references to sub-URI static assets! Otherwise
you may find broken links to images, CSS files, JavaScripts, etc. Please read
<a href="#sub_uri_deployment_uri_fix">How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</a>
for more information.</td>
</tr></table>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_redeploying_restarting_the_ruby_on_rails_application"></span><h3 data-comment-topic="redeploying-restarting-the-ruby-on-rails-application--m5zqc6" data-anchor="_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</h3>
<div class="paragraph"><p>Deploying a new version of a Ruby on Rails application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Apache.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rails
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application during the next request.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example MyCook application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>touch /webapps/mycook/tmp/restart.txt</pre>
</div>
</div>
<div class="paragraph"><p>Please note that, unlike earlier versions of Phusion Passenger, <em>restart.txt</em>
is not automatically deleted. Phusion Passenger checks whether the timestamp
of this file has changed in order to determine whether the application should
be restarted.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_migrations"></span><h3 data-comment-topic="migrations-15238b4" data-anchor="_migrations">3.4. Migrations</h3>
<div class="paragraph"><p>Phusion Passenger is not related to Ruby on Rails migrations in any way. To
run migrations on your deployment server, please login to your deployment
server (e.g. with <em>ssh</em>) and type <span class="monospaced">rake db:migrate RAILS_ENV=production</span> in
a shell console, just like one would normally run migrations.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_capistrano_integration"></span><h3 data-comment-topic="capistrano-integration-1o4cbyq" data-anchor="_capistrano_integration">3.5. Capistrano integration</h3>
<div class="paragraph"><p>See <a href="#capistrano">Capistrano recipe</a>.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_a_rack_based_ruby_application_including_rails_gt_3"></span><h2 data-comment-topic="deploying-a-rack-based-ruby-application-including-rails-3--hcs66f" data-anchor="_deploying_a_rack_based_ruby_application_including_rails_gt_3">4. Deploying a Rack-based Ruby application (including Rails >= 3)</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger supports arbitrary Ruby web applications that follow the
<a href="http://rack.rubyforge.org/">Rack</a> interface.</p></div>
<div class="paragraph"><p>Phusion Passenger assumes that Rack application directories have a certain layout.
Suppose that you have a Rack application in <em>/webapps/rackapp</em>. Then that
folder must contain at least three entries:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>config.ru</em>, a Rackup file for starting the Rack application. This file must contain
the complete logic for initializing the application.
</p>
</li>
<li>
<p>
<em>public/</em>, a folder containing public static web assets, like images and stylesheets.
</p>
</li>
<li>
<p>
<em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will
be explained in a following subsection.
</p>
</li>
</ul></div>
<div class="paragraph"><p>So <em>/webapps/rackapp</em> must, at minimum, look like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/webapps/rackapp
|
+-- config.ru
|
+-- public/
|
+-- tmp/</pre>
</div>
</div>
<div class="paragraph"><p>Suppose you own the domain <em>www.rackapp.com</em>. You can either deploy your application
to the virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.rackapp.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.rackapp.com/rackapp</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">The default <span class="monospaced">RACK_ENV</span> environment in which deployed Rack applications
are run, is “production”. You can change this by changing the
<a href="#rack_env"><em>RackEnv</em></a> configuration option.</td>
</tr></table>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_tutorial_example_writing_and_deploying_a_hello_world_rack_application"></span><h3 data-comment-topic="tutorial-example-writing-and-deploying-a-hello-world-rack-application-axp5z5" data-anchor="_tutorial_example_writing_and_deploying_a_hello_world_rack_application">4.1. Tutorial/example: writing and deploying a Hello World Rack application</h3>
<div class="paragraph"><p>First we create a Phusion Passenger-compliant Rack directory structure:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ mkdir /webapps/rack_example
$ mkdir /webapps/rack_example/public
$ mkdir /webapps/rack_example/tmp</pre>
</div>
</div>
<div class="paragraph"><p>Next, we write a minimal "hello world" Rack application:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ cd /webapps/rack_example
$ some_awesome_editor config.ru
...type in some source code...
$ cat config.ru
app = proc do |env|
[200, { "Content-Type" => "text/html" }, ["hello <b>world</b>"]]
end
run app</pre>
</div>
</div>
<div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
the Apache configuration file:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.rackexample.com
DocumentRoot /webapps/rack_example/public
<Directory /webapps/rack_example/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>And we’re done! After an Apache restart, the above Rack application will be available
under the URL <em>http://www.rackexample.com/</em>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_to_a_virtual_host_8217_s_root_2"></span><h3 data-comment-topic="deploying-to-a-virtual-host-s-root-u9bfax" data-anchor="_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host’s root</h3>
<div class="paragraph"><p>Add a virtual host entry to your Apache configuration file. Make sure that the
following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
The virtual host’s document root must point to your Rack application’s
<em>public</em> folder.
</p>
</li>
<li>
<p>
The Apache per-directory permissions must allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews must be disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.rackapp.com
DocumentRoot /webapps/rackapp/public
<Directory /webapps/rackapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>You may also need to tweak your file/folder permissions. Make sure that the
following folders are readable and executable by Apache:</p></div>
<div class="ulist"><ul>
<li>
<p>
this <em>public</em> folder.
</p>
</li>
<li>
<p>
the application’s <em>config</em> folder.
</p>
</li>
<li>
<p>
all parent folders. That is, /webapps/rackapp and /webapps must also be readable and executable by Apache.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="deploying_rack_to_sub_uri"></span><h3 data-comment-topic="deploying-to-a-sub-uri-zekba6" data-anchor="deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</h3>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>And you want your Rack application, located in <span class="monospaced">/websites/rack</span>, to be accessible from the URL
<em>http://www.phusion.nl/subapp</em>.</p></div>
<div class="paragraph"><p>To do this, you need to perform the following:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Set <span class="monospaced">Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Location /{SUBURI}></span> block.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerBaseURI /{SUBURI}</span>.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}></span> block.
</p>
</li>
<li>
<p>
Inside the Directory block, set <span class="monospaced">Allow from all</span>.
</p>
</li>
<li>
<p>
Inside the Directory block, disable MultiViews.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Here is an example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
# These have been added:
Alias /subapp /websites/rack/public
<Location /subapp>
PassengerBaseURI /subapp
PassengerAppRoot /websites/rack
</Location>
<Directory /websites/rack/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed to the sub-URI.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_redeploying_restarting_the_rack_application"></span><h3 data-comment-topic="redeploying-restarting-the-rack-application--18m41m1" data-anchor="_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</h3>
<div class="paragraph"><p>Deploying a new version of a Rack application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Apache.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rack
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>touch /webapps/rackapp/tmp/restart.txt</pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_rackup_specifications_for_various_web_frameworks"></span><h3 data-comment-topic="rackup-specifications-for-various-web-frameworks-ndsqc2" data-anchor="_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</h3>
<div class="paragraph"><p>This subsection shows example <em>config.ru</em> files for various web frameworks.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_camping"></span><h4 data-comment-topic="camping-1kxexk0" data-anchor="_camping">4.5.1. Camping</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>require 'rubygems'
require 'rack'
require 'camping'
##### Begin Camping application
Camping.goes :Blog
...your application code here...
##### End Camping application
run Rack::Adapter::Camping.new(Blog)</pre>
</div>
</div>
<div class="paragraph"><p>For Camping versions 2.0 and up, using <span class="monospaced">run Blog</span> as the final line will do.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_halcyon"></span><h4 data-comment-topic="halcyon-1ghnpmz" data-anchor="_halcyon">4.5.2. Halcyon</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>require 'rubygems'
require 'halcyon'
$LOAD_PATH.unshift(Halcyon.root / 'lib')
Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
run Halcyon::Runner.new</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_mack"></span><h4 data-comment-topic="mack-miht6b" data-anchor="_mack">4.5.3. Mack</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>ENV["MACK_ENV"] = ENV["RACK_ENV"]
load("Rakefile")
require 'rubygems'
require 'mack'
run Mack::Utils::Server.build_app</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_merb"></span><h4 data-comment-topic="merb-iyj7qy" data-anchor="_merb">4.5.4. Merb</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>require 'rubygems'
require 'merb-core'
Merb::Config.setup(
:merb_root => ::File.expand_path(::File.dirname(__FILE__)),
:environment => ENV['RACK_ENV']
)
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
run Merb::Rack::Application.new</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_ramaze"></span><h4 data-comment-topic="ramaze-boddtj" data-anchor="_ramaze">4.5.5. Ramaze</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>require "rubygems"
require "ramaze"
Ramaze.trait[:essentials].delete Ramaze::Adapter
require "start"
Ramaze.start!
run Ramaze::Adapter::Base</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_sinatra"></span><h4 data-comment-topic="sinatra-1hubto4" data-anchor="_sinatra">4.5.6. Sinatra</h4>
<div class="listingblock">
<div class="content monospaced">
<pre>require 'rubygems'
require 'sinatra'
set :environment, ENV['RACK_ENV'].to_sym
disable :run, :reload
require 'app.rb'
run Sinatra::Application</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_a_wsgi_python_application"></span><h2 data-comment-topic="deploying-a-wsgi-python-application-7aygdl" data-anchor="_deploying_a_wsgi_python_application">5. Deploying a WSGI (Python) application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger supports all WSGI-compliant Python web applications. Suppose that you have a WSGI application in <em>/webapps/wsgiapp</em>. Then that folder must contain at least three entries:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>passenger_wsgi.py</em>, which Phusion Passenger will use as the main entry point for your application. This file must export a WSGI object called <span class="monospaced">application</span>.
</p>
</li>
<li>
<p>
<em>public/</em>, a folder containing public static web assets, like images and stylesheets.
</p>
</li>
<li>
<p>
<em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will be explained in a following subsection.
</p>
</li>
</ul></div>
<div class="paragraph"><p>So <em>/webapps/wsgiapp</em> must, at minimum, look like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/webapps/wsgiapp
|
+-- config.ru
|
+-- public/
|
+-- tmp/</pre>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_tutorial_example_writing_and_deploying_a_hello_world_wsgi_application"></span><h3 data-comment-topic="tutorial-example-writing-and-deploying-a-hello-world-wsgi-application-9ziqy8" data-anchor="_tutorial_example_writing_and_deploying_a_hello_world_wsgi_application">5.1. Tutorial/example: writing and deploying a Hello World WSGI application</h3>
<div class="paragraph"><p>First we create a Phusion Passenger-compliant WSGI directory structure:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ mkdir /webapps/wsgi_example
$ mkdir /webapps/wsgi_example/public
$ mkdir /webapps/wsgi_example/tmp</pre>
</div>
</div>
<div class="paragraph"><p>Next, we write a minimal "hello world" WSGI application:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ cd /webapps/wsgi_example
$ some_awesome_editor passenger_wsgi.py
...type in some source code...
$ cat passenger_wsgi.py
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b"hello world!\n"]</pre>
</div>
</div>
<div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
the Apache configuration file:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.wsgiexample.com
DocumentRoot /webapps/wsgi_example/public
<Directory /webapps/wsgi_example/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>And we’re done! After an Apache restart, the above WSGI application will be available
under the URL <em>http://www.wsgiexample.com/</em>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_to_a_virtual_host_8217_s_root_3"></span><h3 data-comment-topic="deploying-to-a-virtual-host-s-root-zzo4v7" data-anchor="_deploying_to_a_virtual_host_8217_s_root_3">5.2. Deploying to a virtual host’s root</h3>
<div class="paragraph"><p>Add a virtual host entry to your Apache configuration file. Make sure that the
following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
The virtual host’s document root must point to your WSGI application’s
<em>public</em> folder.
</p>
</li>
<li>
<p>
The WSGI per-directory permissions must allow access to this folder.
</p>
</li>
<li>
<p>
MultiViews must be disabled for this folder.
</p>
</li>
</ul></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.wsgiapp.com
DocumentRoot /webapps/wsgiapp/public
<Directory /webapps/wsgiapp/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>You may also need to tweak your file/folder permissions. Make sure that the
following folders are readable and executable by Apache:</p></div>
<div class="ulist"><ul>
<li>
<p>
this <em>public</em> folder.
</p>
</li>
<li>
<p>
the application’s <em>config</em> folder.
</p>
</li>
<li>
<p>
all parent folders. That is, /webapps/wsgiapp and /webapps must also be readable and executable by Apache.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="deploying_python_to_sub_uri"></span><h3 data-comment-topic="deploying-to-a-sub-uri-ayqz96" data-anchor="deploying_python_to_sub_uri">5.3. Deploying to a sub URI</h3>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>And you want your Python application, located in <span class="monospaced">/websites/python</span>, to be accessible from the URL
<em>http://www.phusion.nl/subapp</em>.</p></div>
<div class="paragraph"><p>To do this, you need to perform the following:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Set <span class="monospaced">Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Location /{SUBURI}></span> block.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerBaseURI /{SUBURI}</span>.
</p>
</li>
<li>
<p>
Inside the Location block, set <span class="monospaced">PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}</span>.
</p>
</li>
<li>
<p>
Create a <span class="monospaced"><Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}></span> block.
</p>
</li>
<li>
<p>
Inside the Directory block, set <span class="monospaced">Allow from all</span>.
</p>
</li>
<li>
<p>
Inside the Directory block, disable MultiViews.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Here is an example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
# These have been added:
Alias /subapp /websites/python/public
<Location /subapp>
PassengerBaseURI /subapp
PassengerAppRoot /websites/python
</Location>
<Directory /websites/python/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed to the sub-URI.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_redeploying_restarting_the_wsgi_application"></span><h3 data-comment-topic="redeploying-restarting-the-wsgi-application--na7pmf" data-anchor="_redeploying_restarting_the_wsgi_application">5.4. Redeploying (restarting the WSGI application)</h3>
<div class="paragraph"><p>Deploying a new version of a WSGI application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Apache.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the WSGI
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>touch /webapps/wsgiapp/tmp/restart.txt</pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_a_node_js_application"></span><h2 data-comment-topic="deploying-a-node-js-application-882ecy" data-anchor="_deploying_a_node_js_application">6. Deploying a Node.js application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Please refer to <a href="https://github.com/phusion/passenger/wiki/Phusion-Passenger%3A-Node.js-tutorial">the Node.js tutorial</a>.</p></div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deploying_a_meteor_application"></span><h2 data-comment-topic="deploying-a-meteor-application-mxfmir" data-anchor="_deploying_a_meteor_application">7. Deploying a Meteor application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Please refer to <a href="https://github.com/phusion/passenger/wiki/Phusion-Passenger:-Meteor-tutorial">the Meteor tutorial</a>.</p></div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_configuring_phusion_passenger"></span><h2 data-comment-topic="configuring-phusion-passenger-11oztoe" data-anchor="_configuring_phusion_passenger">8. Configuring Phusion Passenger</h2>
<div class="sectionbody">
<div class="paragraph"><p>After installation, Phusion Passenger does not need any further configurations.
Nevertheless, the system administrator may be interested in changing
Phusion Passenger’s behavior. Phusion Passenger’s Apache module supports the
following configuration options:</p></div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerroot_lt_directory_gt"></span><h3 data-comment-topic="passengerroot-directory--sere8l" data-anchor="_passengerroot_lt_directory_gt">8.1. PassengerRoot <directory></h3>
<div class="paragraph"><p>The location to the Phusion Passenger root directory. This configuration option
is essential to Phusion Passenger, and allows Phusion Passenger to locate its own
data files. The correct value is given by the installer.</p></div>
<div class="paragraph"><p>If you’ve moved Phusion Passenger to a different directory then you need to update
this option as well. Please read
<a href="#moving_phusion_passenger">Moving Phusion Passenger to a different directory</a> for more information.</p></div>
<div class="paragraph"><p>This required option may only occur once, in the global server configuration.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerDefaultRuby"></span><h3 data-comment-topic="passengerdefaultruby-and-passengerruby-7zblp8" data-anchor="PassengerDefaultRuby">8.2. PassengerDefaultRuby <filename></h3>
<div class="paragraph"><p><strong>Introduced in version 4.0.0.</strong></p></div>
<div class="paragraph"><p>This option specifies the default Ruby interpreter to use for web apps as well as for all sorts of internal Phusion Passenger helper scripts, e.g. the one used by <a href="#PassengerPreStart">PassengerPreStart</a>. Please see <a href="#PassengerRuby">PassengerRuby</a> for more information, as well as how it relates to <a href="#PassengerRuby">PassengerRuby</a>.</p></div>
<div class="paragraph"><p>This option may occur in the global server configuration. The default value is <em>ruby</em>, meaning that the Ruby interpreter will be looked up according to the <span class="monospaced">PATH</span> environment variable.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deployment_options"></span><h3 data-comment-topic="deployment-options-1unzrll" data-anchor="_deployment_options">8.3. Deployment options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerEnabled"></span><h4 data-comment-topic="passengerenabled-on-off--74rzth" data-anchor="PassengerEnabled">8.3.1. PassengerEnabled <on|off></h4>
<div class="paragraph"><p>You can set this option to <em>off</em> to completely disable Phusion Passenger for
a certain location. This is useful if, for example, you want to integrate a PHP
application into the same virtual host as a Rails application.</p></div>
<div class="paragraph"><p>Suppose that you have a Rails application in <em>/apps/foo</em>. Suppose that you’ve
dropped Wordpress — a blogging application written in PHP — in
<em>/apps/foo/public/wordpress</em>. You can then configure Phusion Passenger as
follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
<Directory /apps/foo/public/wordpress>
PassengerEnabled off
AllowOverride all # <-- Makes Wordpress's .htaccess file work.
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>This way, Phusion Passenger will not interfere with Wordpress.</p></div>
<div class="paragraph"><p><em>PassengerEnabled</em> may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>on</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerRuby"></span><h4 data-comment-topic="passengerruby-filename--1r3fv73" data-anchor="PassengerRuby">8.3.2. PassengerRuby <filename></h4>
<div class="paragraph"><p>The <span class="monospaced">PassengerDefaultRuby</span> and <span class="monospaced">PassengerRuby</span> directives specify the Ruby interpreter to use. Similarly, the <span class="monospaced">PassengerPython</span> and <span class="monospaced">PassengerNodejs</span> directives are for specifying the Python interpreter and the Node.js command, respectively.</p></div>
<div class="paragraph"><p>The relationship between <span class="monospaced">PassengerDefaultRuby</span> and <span class="monospaced">PassengerRuby</span> is as follows:</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">PassengerDefaultRuby</span> may only occur in the global server configuration.
</p>
</li>
<li>
<p>
<span class="monospaced">PassengerRuby</span> may occur everywhere: in the global server configuration, in <span class="monospaced"><VirtualHost></span>, in <span class="monospaced"><Directory></span>, in <span class="monospaced"><Location></span>, and in <em>.htaccess</em> if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
<li>
<p>
You don’t <strong>have</strong> to specify <span class="monospaced">PassengerRuby</span>. In this case <span class="monospaced">PassengerDefaultRuby</span> is used as the Ruby interpreter. But if you do specify <span class="monospaced">PassengerRuby</span> then it will override <span class="monospaced">PassengerDefaultRuby</span> in that context. This allows you to use <span class="monospaced">PassengerRuby</span> to specify a different Ruby interpreter on a per-application basis.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Phusion Passenger not only uses Ruby to run web apps, but also for running certain helper tools that are written in Ruby, e.g. the internal helper script used by <a href="#PassengerPreStart">PassengerPreStart</a>. These tools are always run using <span class="monospaced">PassengerDefaultRuby</span>, never by <span class="monospaced">PassengerRuby</span>. <span class="monospaced">PassengerRuby</span> is only used for running web apps. You can learn more about the internal helper scripts in <a href="#relationship_with_ruby">Phusion Passenger and its relationship with Ruby</a>.</p></div>
<div class="paragraph"><p>It is okay if <span class="monospaced">PassengerDefaultRuby</span> refers to a different Ruby interpreter than the one you originally installed Phusion Passenger with. This too is explained in <a href="#relationship_with_ruby">Phusion Passenger and its relationship with Ruby</a>.</p></div>
<div class="paragraph"><p>The reason why <span class="monospaced">PassengerDefaultRuby</span> exists at all is because limitations in the Apache API prevents us from implementing the same behavior using only the <span class="monospaced">PassengerRuby</span> directive.</p></div>
<div class="paragraph"><p>There is no <span class="monospaced">PassengerDefaultPython</span> etc because there are no Phusion Passenger tools written in Python. As such, having <span class="monospaced">PassengerPython</span> is enough.</p></div>
<div class="paragraph"><p>The following example illustrates how it works and how you can use these options to specify different interpreters for different web apps.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># Use Ruby 1.8.7 by default.
PassengerDefaultRuby /usr/bin/ruby1.8
# Use Python 2.6 by default.
PassengerPython /usr/bin/python2.6
# Use /usr/bin/node by default.
PassengerNodejs /usr/bin/node;
<VirtualHost *:80>
# This Rails web app will use Ruby 1.8.7
ServerName www.foo.com
DocumentRoot /webapps/foo/public
</VirtualHost>
<VirtualHost *:80>
# This Rails web app will use Ruby 1.9.3, as installed by RVM
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3/ruby
ServerName www.bar.com
DocumentRoot /webapps/bar/public
# If you have a web app deployed in a sub-URI, customize
# PassengerRuby/PassengerPython inside a <Location> block.
# The web app under www.bar.com/blog will use JRuby 1.7.1
Alias /blog /websites/blog/public
<Location /blog>
PassengerBaseURI /blog
PassengerAppRoot /websites/blog
PassengerRuby /usr/local/rvm/wrappers/jruby-1.7.1/ruby
</Location>
<Directory /websites/blog/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
# This Flask web app will use Python 3.0
PassengerPython /usr/bin/python3.0
ServerName www.baz.com
DocumentRoot /webapps/baz/public
</VirtualHost></pre>
</div>
</div>
<div class="paragraph">
<div class="title">RVM helper tool</div>
<p>Phusion Passenger provides the <span class="monospaced">passenger-config --ruby-command</span> tool for figuring out the correct command for invoking a specific Ruby interpreter. This is especially useful for RVM users. Suppose that you have both Ruby 1.8.7 and Ruby 1.9.3 installed through RVM, and you want to know the correct commands for each Ruby interpreter.</p>
</div>
<div class="paragraph"><p>For this purpose we’ll want to invoke <span class="monospaced">passenger-config</span> using its full path, because each time you <span class="monospaced">rvm use</span> a different Ruby interpreter, RVM changes <span class="monospaced">$PATH</span>. If you did not install Phusion Passenger through the generic tarball installation method, then here’s how you can figure out where <span class="monospaced">passenger-config</span> is:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ which passenger-config
/opt/passenger/bin/passenger-config</pre>
</div>
</div>
<div class="paragraph"><p>Now, switch to all the RVM Ruby interpreters you want to use. In each interpreter, invoke <span class="monospaced">passenger-config --ruby-command</span>. For Ruby 1.8.7:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ rvm use 1.8.7
$ /opt/passenger/bin/passenger-config --ruby-command
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/local/rvm/wrappers/ruby-1.8.7-p358/ruby
Version: ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
To use in Apache: PassengerRuby /usr/local/rvm/wrappers/ruby-1.8.7-p358/ruby
To use in Nginx : passenger_ruby /usr/local/rvm/wrappers/ruby-1.8.7-p358/ruby
To use with Standalone: /usr/local/rvm/wrappers/ruby-1.8.7-p358/ruby /opt/passenger/bin/passenger start
## Notes for RVM users
Do you want to know which command to use for a different Ruby interpreter? 'rvm use' that Ruby interpreter, then re-run 'passenger-config --ruby-command'.</pre>
</div>
</div>
<div class="paragraph"><p>Then, for Ruby 1.9.3:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ rvm use 1.9.3
$ /opt/passenger/bin/passenger-config --ruby-command
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby
Version: ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]
To use in Apache: PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby
To use in Nginx : passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby
To use with Standalone: /usr/local/rvm/wrappers/ruby-1.9.3-p392/ruby /opt/passenger/bin/passenger start
## Notes for RVM users
Do you want to know which command to use for a different Ruby interpreter? 'rvm use' that Ruby interpreter, then re-run 'passenger-config --ruby-command'.</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerpython_lt_filename_gt"></span><h4 data-comment-topic="passengerpython-filename--1ssesv3" data-anchor="_passengerpython_lt_filename_gt">8.3.3. PassengerPython <filename></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.0.</strong></p></div>
<div class="paragraph"><p>This option allows one to specify the Python interpreter to use. See <a href="#PassengerRuby">PassengerRuby</a> for more information. The default value is <em>python</em>, meaning that the Python interpreter will be looked up according to the <span class="monospaced">PATH</span> environment variable.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengernodejs_lt_filename_gt"></span><h4 data-comment-topic="passengernodejs-filename--2mjb1j" data-anchor="_passengernodejs_lt_filename_gt">8.3.4. PassengerNodejs <filename></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.24.</strong></p></div>
<div class="paragraph"><p>This option allows one to specify the Node.js command to use. See <a href="#PassengerRuby">PassengerRuby</a> for more information. The default value is <em>node</em>, meaning that the Node.js command will be looked up according to the <span class="monospaced">PATH</span> environment variable.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerAppEnv"></span><h4 data-comment-topic="passengerappenv-string--s3ojlc" data-anchor="PassengerAppEnv">8.3.5. PassengerAppEnv <string></h4>
<div class="paragraph"><p>This option sets the value of the following environment variables:</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">RAILS_ENV</span>
</p>
</li>
<li>
<p>
<span class="monospaced">RACK_ENV</span>
</p>
</li>
<li>
<p>
<span class="monospaced">WSGI_ENV</span>
</p>
</li>
<li>
<p>
<span class="monospaced">NODE_ENV</span>
</p>
</li>
<li>
<p>
<span class="monospaced">PASSENGER_APP_ENV</span>
</p>
</li>
</ul></div>
<div class="paragraph"><p>Some web frameworks, for example Rails and Connect.js, adjust their behavior according to the value in one of these environment variables.</p></div>
<div class="paragraph"><p>Phusion Passenger for Apache sets the default value to <strong>production</strong>. If you’re developing an Rails application then you should set this to <span class="monospaced">development</span>.</p></div>
<div class="paragraph"><p>If you want to set other environment variables, please refer to <a href="#env_vars_passenger_apps">Setting environment variables for Phusion Passenger-served apps</a>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="rails_env"></span><h4 data-comment-topic="railsenv-string--1b0xxvu" data-anchor="rails_env">8.3.6. RailsEnv <string></h4>
<div class="paragraph"><p>An alias for <a href="#PassengerAppEnv">PassengerAppEnv</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="rack_env"></span><h4 data-comment-topic="rackenv-string--vve9py" data-anchor="rack_env">8.3.7. RackEnv <string></h4>
<div class="paragraph"><p>An alias for <a href="#PassengerAppEnv">PassengerAppEnv</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerAppRoot"></span><h4 data-comment-topic="passengerapproot-path-to-root--uf24yd" data-anchor="PassengerAppRoot">8.3.8. PassengerAppRoot <path/to/root></h4>
<div class="paragraph"><p>By default, Phusion Passenger assumes that the application’s root directory
is the parent directory of the <em>public</em> directory. This option allows one to
specify the application’s root independently from the DocumentRoot, which
is useful if the <em>public</em> directory lives in a non-standard place.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
<div class="paragraph"><p>Example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost test.host>
DocumentRoot /var/rails/zena/sites/example.com/public
PassengerAppRoot /var/rails/zena # <-- normally Phusion Passenger would
# have assumed that the application
# root is "/var/rails/zena/sites/example.com"
</VirtualHost></pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerBaseURI"></span><h4 data-comment-topic="passengerbaseuri-uri--97i9mm" data-anchor="PassengerBaseURI">8.3.9. PassengerBaseURI <uri></h4>
<div class="paragraph"><p>Used to specify that the given URI is a Phusion Passenger-served application. Please refer
to the following sections for examples:</p></div>
<div class="ulist"><ul>
<li>
<p>
<a href="#deploying_rails_to_sub_uri">Deploying Rails 1.x and 2.x to a sub URI</a>
</p>
</li>
<li>
<p>
<a href="#deploying_rack_to_sub_uri">Deploying Rack (including Rails >= 3) to a sub URI</a>
</p>
</li>
<li>
<p>
<a href="#deploying_python_to_sub_uri">Deploying Python to a sub URI</a>
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerrestartdir_lt_directory_gt"></span><h4 data-comment-topic="passengerrestartdir-directory--1fmhmv0" data-anchor="_passengerrestartdir_lt_directory_gt">8.3.10. PassengerRestartDir <directory></h4>
<div class="paragraph"><p>As described in the deployment chapters of this document, Phusion Passenger
checks the file <em>tmp/restart.txt</em> in the applications'
<a href="#application_root">root directory</a> for restarting applications. Sometimes it
may be desirable for Phusion Passenger to look in a different directory instead,
for example for security reasons (see below). This option allows you to
customize the directory in which <em>restart.txt</em> is searched for.</p></div>
<div class="paragraph"><p>You may specify <em>PassengerRestartDir</em> in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverrides Options</span> is enabled.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
<div class="paragraph"><p>You can either set it to an absolute directory, or to a directory relative to
the <a href="#application_root">application root</a>. Examples:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.foo.com
# Phusion Passenger will check for /apps/foo/public/tmp/restart.txt
DocumentRoot /apps/foo/public
</VirtualHost>
<VirtualHost *:80>
ServerName www.bar.com
DocumentRoot /apps/bar/public
# An absolute filename is given; Phusion Passenger will
# check for /restart_files/bar/restart.txt
PassengerRestartDir /restart_files/bar
</VirtualHost>
<VirtualHost *:80>
ServerName www.baz.com
DocumentRoot /apps/baz/public
# A relative filename is given; Phusion Passenger will
# check for /apps/baz/restart_files/restart.txt
#
# Note that this directory is relative to the APPLICATION ROOT, *not*
# the value of DocumentRoot!
PassengerRestartDir restart_files
</VirtualHost></pre>
</div>
</div>
<div class="paragraph">
<div class="title">What are the security reasons for wanting to customize PassengerRestartDir?</div>
<p>Touching restart.txt will cause Phusion Passenger to restart the application.
So anybody who can touch restart.txt can effectively cause a Denial-of-Service
attack by touching restart.txt over and over. If your web server or one of your
web applications has the permission to touch restart.txt, and one of them has a
security flaw which allows an attacker to touch restart.txt, then that will
allow the attacker to cause a Denial-of-Service.</p>
</div>
<div class="paragraph"><p>You can prevent this from happening by pointing PassengerRestartDir to a
directory that’s readable by Apache, but only writable by administrators.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerRollingRestarts"></span><h4 data-comment-topic="passengerrollingrestarts" data-anchor="PassengerRollingRestarts">8.3.11. PassengerRollingRestarts <on|off></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Enables or disables support for rolling restarts through restart.txt. Normally when you
restart an application by touching restart.txt, Phusion Passenger would
shut down all application processes and spawn a new one. The spawning
of a new application process could take a while, and any requests that
come in during this time will be blocked until this first application
process has spawned.</p></div>
<div class="paragraph"><p>But when rolling restarts are enabled, Phusion Passenger Enterprise will:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Spawn a new process in the background.
</p>
</li>
<li>
<p>
When it’s done spawning, Phusion Passenger Enterprise will replace one of the old processes with this newly spawned one.
</p>
</li>
<li>
<p>
Step 1 and 2 are repeated until all processes have been replaced.
</p>
</li>
</ol></div>
<div class="paragraph"><p>This way, visitors will not experience any delays when you are restarting your application. This allows you to, for example, upgrade your application often without degrading user experience.</p></div>
<div class="paragraph"><p>Rolling restarts have a few caveat however that you should be aware of:</p></div>
<div class="ulist"><ul>
<li>
<p>
Upgrading an application sometimes involves upgrading the database schema.
With rolling restarts, there may be a point in time during which processes
belonging to the previous version and processes belonging to the new version
both exist at the same time. Any database schema upgrades you perform must
therefore be backwards-compatible with the old application version.
</p>
</li>
<li>
<p>
Because there’s no telling which process will serve a request, users may
not see changes brought about by the new version until all processes have
been restarted. It is for this reason that you should not use rolling
restarts in development, only in production.
</p>
</li>
</ul></div>
<div class="paragraph"><p>If Passenger Enterprise could not rolling restart a process (let’s call it <em>A</em>) because it is unable to spawn a new process (let’s call it <em>B</em>), then Passenger Enterprise will give up trying to rolling restart that particular process <em>A</em>. What happens next depends on whether <a href="#PassengerResistDeploymentErrors">deployment error resistance</a> is enabled:</p></div>
<div class="ulist"><ul>
<li>
<p>
If deployment error resistance is disabled (the default), then Passenger Enterprise will proceed with trying to restart the remaining processes.
</p>
</li>
<li>
<p>
If deployment error resistance is enabled, the Passenger Enterprise will give up rolling restarting immediately. The application group will be put into Deployment Error Resistance Mode.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Please note that <span class="monospaced">PassengerRollingRestarts</span> is completely unrelated to the <span class="monospaced">passenger-config restart-app</span> command. That command always initiates a blocking restart, unless <span class="monospaced">--rolling-restart</span> is given.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerResistDeploymentErrors"></span><h4 data-comment-topic="passengerresistdeploymenterrors" data-anchor="PassengerResistDeploymentErrors">8.3.12. PassengerResistDeploymentErrors <on|off></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Enables or disables resistance against deployment errors.</p></div>
<div class="paragraph"><p>Suppose you’ve upgraded your application and you’ve issues a command to restart it (by touching restart.txt), but the application code contains an error that prevents Phusion Passenger from successfully spawning a process (e.g. a syntax error). Phusion Passenger would normally display an error message in response to this.</p></div>
<div class="paragraph"><p>By enabling deployment error resistance, Phusion Passenger Enterprise would instead do this:</p></div>
<div class="ulist"><ul>
<li>
<p>
It passes the request to one of the existing application processes (that belong to the previous version of the application). The visitor will not see a Phusion Passenger process spawning error message.
</p>
</li>
<li>
<p>
It logs the error to the global web server error log file.
</p>
</li>
<li>
<p>
It sets an internal flag (Deployment Error Resistance Mode) so that no processes for this application will be spawned (even when the current traffic would normally result in more processes being spawned) and no processes will be idle cleaned. Processes <strong>could</strong> still be shutdown because of other events, e.g. because their <a href="#PassengerMemoryLimit">memory limit</a> have been reached. You can see whether the flag is set by invoking <span class="monospaced">passenger-status</span>. If you see the message "Resisting deployment error" then the flag is set.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This way, visitors will suffer minimally from deployment errors. Phusion Passenger will attempt to restart the application again next time restart.txt is touched.</p></div>
<div class="paragraph"><p>Enabling deployment error resistance only works if <a href="#PassengerRollingRestarts">rolling restart</a> is also enabled.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_process_spawning_options"></span><h3 data-comment-topic="process-spawning-options-v2vscm" data-anchor="_process_spawning_options">8.4. Process spawning options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerSpawnMethod"></span><h4 data-comment-topic="passengerspawnmethod-string--sodg2y" data-anchor="PassengerSpawnMethod">8.4.1. PassengerSpawnMethod <string></h4>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip">
</td>
<td class="content">
<div class="title">"What spawn method should I use?"</div>
<div class="paragraph"><p>This subsection attempts to describe spawn methods, but it’s okay if you don’t (want to)
understand it, as it’s mostly a technical detail. You can basically follow this rule of thumb:</p></div>
<div class="sidebarblock">
<div class="content">
<div class="paragraph"><p>If your application works on Mongrel or Thin, but not on Phusion Passenger, then set
<span class="monospaced">PassengerSpawnMethod</span> to <em>direct</em>. Otherwise, leave it at <em>smart</em> (the default).</p></div>
</div>
</div>
<div class="paragraph"><p>However, we do recommend you to try to understand it. The <em>smart</em> spawn
method bring many benefits.</p></div>
</td>
</tr></table>
</div>
<div class="paragraph"><p>Internally, Phusion Passenger spawns multiple Ruby application processes in order to handle
requests. But there are multiple ways with which processes can be spawned, each having
its own set of pros and cons. Supported spawn methods are:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<em>smart</em>
</dt>
<dd>
<p>
This spawning method caches code using the app preloader. Framework code is not
cached between multiple applications, although it is cached within
instances of the same application. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what smart spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
Smart spawning caches code where possible to speed up the respawn process
and is compatible with most applications</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
It is possible that it may be incompatible with some applications</p></div>
</dd>
<dt class="hdlist1">
<em>direct</em>
</dt>
<dd>
<p>
This spawning method is similar to the one used in Mongrel Cluster. It does not
perform any code caching at all. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what direct spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
Direct spawning is guaranteed to be compatible with all applications
and libraries.</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
Much slower than smart spawning. Every spawn action will be equally slow, though no slower than
the startup time of a single server in Mongrel Cluster. Direct spawning will also
render <a href="#reducing_memory_usage">Ruby Enterprise Edition’s memory reduction technology</a> useless.</p></div>
</dd>
</dl></div>
<div class="sidebarblock">
<div class="content">
<div class="paragraph"><p>As of Phusion Passenger 4.0, <em>conservative</em> spawning was renamed to <em>direct</em> and <em>smart-lv2</em> was renamed
to <em>smart</em>. The old <em>smart</em> spawning has been removed in favor of the new version.</p></div>
</div>
</div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>smart</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerLoadShellEnvvars"></span><h4 data-comment-topic="passengerloadshellenvvars-on-off--1290yz1" data-anchor="PassengerLoadShellEnvvars">8.4.2. PassengerLoadShellEnvvars <on|off></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.20.</strong></p></div>
<div class="paragraph"><p>Enables or disables the loading of shell environment variables before spawning the application.</p></div>
<div class="paragraph"><p>If this option is turned on, and the user’s shell is <span class="monospaced">bash</span>, then applications are loaded by running them with <span class="monospaced">bash -l -c</span>. Otherwise, they are loaded by running them directly from the <span class="monospaced">PassengerHelperAgent</span> process.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>on</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_security_options"></span><h3 data-comment-topic="security-options-1pb75ho" data-anchor="_security_options">8.5. Security options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerUserSwitching"></span><h4 data-comment-topic="passengeruserswitching" data-anchor="PassengerUserSwitching">8.5.1. PassengerUserSwitching <on|off></h4>
<div class="paragraph"><p>Whether to enable <a href="#user_switching">user switching support</a>.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>on</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerUser"></span><h4 data-comment-topic="passengeruser" data-anchor="PassengerUser">8.5.2. PassengerUser <username></h4>
<div class="paragraph"><p>If <a href="#user_switching">user switching support</a> is enabled, then Phusion Passenger will
by default run the web application as the owner of the file <em>config/environment.rb</em>
(for Rails apps) or <em>config.ru</em> (for Rack apps). This option allows you to override
that behavior and explicitly set a user to run the web application as, regardless
of the ownership of <em>environment.rb</em>/<em>config.ru</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerGroup"></span><h4 data-comment-topic="passengergroup" data-anchor="PassengerGroup">8.5.3. PassengerGroup <group name></h4>
<div class="paragraph"><p>If <a href="#user_switching">user switching support</a> is enabled, then Phusion Passenger will
by default run the web application as the primary group of the owner of the file
<em>config/environment.rb</em> (for Rails apps) or <em>config.ru</em> (for Rack apps). This option
allows you to override that behavior and explicitly set a group to run the web application
as, regardless of the ownership of <em>environment.rb</em>/<em>config.ru</em>.</p></div>
<div class="paragraph"><p><em><group name></em> may also be set to the special value <em>!STARTUP_FILE!</em>, in which case
the web application’s group will be set to <em>environment.rb</em>/<em>config.ru</em>'s group.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerDefaultUser"></span><h4 data-comment-topic="passengerdefaultuser" data-anchor="PassengerDefaultUser">8.5.4. PassengerDefaultUser <username></h4>
<div class="paragraph"><p>Phusion Passenger enables <a href="#user_switching">user switching support</a> by default.
This configuration option allows one to specify the user that applications must
run as, if user switching fails or is disabled.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>nobody</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerDefaultGroup"></span><h4 data-comment-topic="passengerdefaultgroup" data-anchor="PassengerDefaultGroup">8.5.5. PassengerDefaultGroup <group name></h4>
<div class="paragraph"><p>Phusion Passenger enables <a href="#user_switching">user switching support</a> by default.
This configuration option allows one to specify the group that applications must
run as, if user switching fails or is disabled.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is the primary group of the user specifified by
<a href="#PassengerDefaultUser">PassengerDefaultUser</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerFriendlyErrorPages"></span><h4 data-comment-topic="passengerfriendlyerrorpages" data-anchor="PassengerFriendlyErrorPages">8.5.6. PassengerFriendlyErrorPages <on|off></h4>
<div class="paragraph"><p>Phusion Passenger can display friendly error pages whenever an application fails
to start. This friendly error page presents the startup error message, some
suggestions for solving the problem, and a backtrace. This feature is very useful
during application development and useful for less experienced system administrators,
but the page might reveal potentially sensitive information, depending on the
application. Experienced system administrators who are using Phusion Passenger
on serious production servers should consider turning this feature off.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>on</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_resource_control_and_optimization_options"></span><h3 data-comment-topic="resource-control-and-optimization-options-zu2f7u" data-anchor="_resource_control_and_optimization_options">8.6. Resource control and optimization options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxPoolSize"></span><h4 data-comment-topic="passengermaxpoolsize-integer--am64q8" data-anchor="PassengerMaxPoolSize">8.6.1. PassengerMaxPoolSize <integer></h4>
<div class="paragraph"><p>The maximum number of <a href="#application_process">application processes</a> that may
simultaneously exist. A larger number results in higher memory usage,
but improves the ability to handle concurrent HTTP requests.</p></div>
<div class="paragraph"><p>The optimal value depends on your system’s hardware and your workload. You can learn more at the Phusion article <a href="http://blog.phusion.nl/2013/03/12/tuning-phusion-passengers-concurrency-settings/">Tuning Phusion Passenger’s concurrency settings</a>.</p></div>
<div class="paragraph"><p>If you find that your server is running out of memory then you should lower this value.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>6</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMinInstances"></span><h4 data-comment-topic="passengermininstances-integer--wegq6b" data-anchor="PassengerMinInstances">8.6.2. PassengerMinInstances <integer></h4>
<div class="paragraph"><p>This specifies the minimum number of application processes that should exist for a
given application. You should set this option to a
non-zero value if you want to avoid potentially long startup times after a website
has been <a href="#idle_process">idle</a> for an extended period.</p></div>
<div class="paragraph"><p>Please note that this option does <strong>not</strong> pre-start application processes during Apache
startup. It just makes sure that when the application is first accessed:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
at least the given number of processes will be spawned.
</p>
</li>
<li>
<p>
the given number of processes will be kept around even when processes are being
idle cleaned (see <a href="#PassengerPoolIdleTime">PassengerPoolIdleTime</a>).
</p>
</li>
</ol></div>
<div class="paragraph"><p>If you want to pre-start application processes during Apache startup, then you should use the <a href="#PassengerPreStart">PassengerPreStart</a> directive, possibly in combination with
<em>PassengerMinInstances</em>. This behavior might seem counter-intuitive at first sight,
but <a href="#PassengerPreStart">PassengerPreStart</a> explains the rationale behind it.</p></div>
<div class="paragraph"><p>For example, suppose that you have the following configuration:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>PassengerMaxPoolSize 15
PassengerPoolIdleTime 10
<VirtualHost *:80>
ServerName foobar.com
DocumentRoot /webapps/foobar/public
PassengerMinInstances 3
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>When you start Apache, there are 0 application processes for <em>foobar.com</em>. Things will
stay that way until someone visits <em>foobar.com</em>. Suppose that there is only 1 visitor.
1 application process will be started immediately to serve the visitor, while 2 will
be spawned in the background. After 10 seconds, when the idle timeout has
been reached, these 3 application processes will not be cleaned up.</p></div>
<div class="paragraph"><p>Now suppose that there’s a sudden spike of traffic, and 100 users visit <em>foobar.com</em>
simultanously. Phusion Passenger will start 12 more application processes. After the idle
timeout of 10 seconds have passed, Phusion Passenger will clean up 12 application
processes, keeping 3 processes around.</p></div>
<div class="paragraph"><p>The PassengerMinInstances option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>1</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxInstances"></span><h4 data-comment-topic="passengermaxinstances" data-anchor="PassengerMaxInstances">8.6.3. PassengerMaxInstances <integer></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>The maximum number of application processes that may simultaneously exist
for an application. This helps to make sure that a single application
will not occupy all available slots in the application pool.</p></div>
<div class="paragraph"><p>This value must be less than <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>. A value of 0
means that there is no limit placed on the number of processes a single application
may spawn, i.e. only the global limit of <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
will be enforced.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip">
</td>
<td class="content">
<div class="title">Practical usage example</div>
<div class="paragraph"><p>Suppose that you’re hosting two web applications on your server, a personal
blog and an e-commerce website. You’ve set <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
to 10. The e-commerce website is more important to you. You can then set
<em>PassengerMaxInstances</em> to 3 for your blog, so that it will never spawn more
than 3 processes, even if it suddenly gets a lot of traffic. Your e-commerce website
on the other hand will be free to spawn up to 10 processes if it gets a lot of traffic.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengermaxinstancesperapp_lt_integer_gt"></span><h4 data-comment-topic="passengermaxinstancesperapp" data-anchor="_passengermaxinstancesperapp_lt_integer_gt">8.6.4. PassengerMaxInstancesPerApp <integer></h4>
<div class="paragraph"><p>The maximum number of application processes that may simultaneously exist
for a single application. This helps to make sure that a single application
will not occupy all available slots in the application pool.</p></div>
<div class="paragraph"><p>This value must be less than <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>. A value of 0
means that there is no limit placed on the number of processes a single application
may use, i.e. only the global limit of <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
will be enforced.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>0</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip">
</td>
<td class="content">
<div class="title">Practical usage example</div>
<div class="paragraph"><p>Suppose that you’re hosting two blogs (blog A and B) on your server, and that
you’ve set <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a> to 10. Under normal
circumstances, if blog A suddenly gets a lot of traffic, then A will use all 10
pool slots. If blog B suddenly gets some traffic, then it will only be able to
use 1 pool slot (forcefully releasing 1 slot from A) until A’s traffic has
settled down and it has released more pool slots.</p></div>
<div class="paragraph"><p>If you consider both blogs equally important, then you can set
<em>PassengerMaxInstancesPerApp</em> to 5. This way, both blogs will never use more
than 5 pool slots.</p></div>
</td>
</tr></table>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">
<div class="title">Relation with PassengerMaxInstances</div>
<div class="paragraph"><p>Unlike <a href="#PassengerMaxInstances">PassengerMaxInstances</a>, this configuration
option is global and applies to all applications. <em>PassengerMaxInstances</em> on the
other hand is per-virtual host.</p></div>
<div class="paragraph"><p>Suppose that you’re hosting two web applications on your server, a personal
blog and an e-commerce website. You’ve set <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
to 10. The e-commerce website is more important to you. You can then set
<em>PassengerMaxInstances</em> to 3 for your blog, so that it will never use more than
3 pool slots, even if it suddenly gets a lot of traffic. Your e-commerce website
on the other hand will be free to use up all 10 slots if it gets a lot of traffic.</p></div>
<div class="paragraph"><p>In summary, <em>PassengerMaxInstancesPerApp</em> divides the pool equally among the
different web applications, while <em>PassengerMaxInstances</em> allows one to divide
the pool unequally, according to each web application’s relative importance.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerPoolIdleTime"></span><h4 data-comment-topic="passengerpoolidletime-integer--a3gunq" data-anchor="PassengerPoolIdleTime">8.6.5. PassengerPoolIdleTime <integer></h4>
<div class="paragraph"><p>The maximum number of seconds that an application process may be idle. That is,
if an application process hasn’t received any traffic after the given number of
seconds, then it will be shutdown in order to conserve memory.</p></div>
<div class="paragraph"><p>Decreasing this value means that applications will have to be spawned
more often. Since spawning is a relatively slow operation, some visitors may
notice a small delay when they visit your Rails/Rack website. However, it will also
free up resources used by applications more quickly.</p></div>
<div class="paragraph"><p>The optimal value depends on the average time that a visitor spends on a single
Rails/Rack web page. We recommend a value of <span class="monospaced">2 * x</span>, where <span class="monospaced">x</span> is the average
number of seconds that a visitor spends on a single Rails/Rack web page. But your
mileage may vary.</p></div>
<div class="paragraph"><p>When this value is set to <em>0</em>, application processes will not be shutdown unless
it’s really necessary, i.e. when Phusion Passenger is out of application processes
for a given application and one of the <a href="#inactive_process">inactive application processes</a> needs to
make place for another application process. Setting the value to 0 is
recommended if you’re on a non-shared host that’s only running a few
applications, each which must be available at all times.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default value is <em>300</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxPreloaderIdleTime"></span><h4 data-comment-topic="railsappspawneridletime-integer--1awgog1" data-anchor="PassengerMaxPreloaderIdleTime">8.6.6. PassengerMaxPreloaderIdleTime <integer></h4>
<div class="paragraph"><p>The ApplicationSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
Phusion Passenger do. That is, it will automatically shutdown if it hasn’t done
anything for a given period.</p></div>
<div class="paragraph"><p>This option allows you to set the ApplicationSpawner server’s idle timeout, in
seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
<div class="paragraph"><p>Setting a higher value will mean that the ApplicationSpawner server is kept around
longer, which may slightly increase memory usage. But as long as the
ApplicationSpawner server is running, the time to spawn a Ruby on Rails backend
process only takes about 10% of the time that is normally needed, assuming that
you’re using the <em>smart</em> or <em>smart-lv2</em> <a href="#PassengerSpawnMethod">spawning method</a>. So if your
system has enough memory, is it recommended that you set this option to a high
value or to <em>0</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>300</em> (5 minutes).</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerstarttimeout_lt_seconds_gt"></span><h4 data-comment-topic="passengerstarttimeout-seconds--ihnfku" data-anchor="_passengerstarttimeout_lt_seconds_gt">8.6.7. PassengerStartTimeout <seconds></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.15.</strong></p></div>
<div class="paragraph"><p>Specifies a timeout for the startup of application processes. If an application process fails to start within the timeout period then it will be forcefully killed with SIGKILL, and the error will be logged.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>90</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerConcurrencyModel"></span><h4 data-comment-topic="passengerconcurrencymodel-process-thread--1eipofj" data-anchor="PassengerConcurrencyModel">8.6.8. PassengerConcurrencyModel <process|thread></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 4.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Specifies the I/O concurrency model that should be used for application processes. Phusion Passenger supports two concurrency models:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>process</em> - single-threaded, multi-processed I/O concurrency. Each application process only has a single thread and can only handle 1 request at a time. This is the concurrency model that Ruby applications traditionally used. It has excellent compatiblity (can work with applications that are not designed to be thread-safe) but is unsuitable for workloads in which the application has to wait for a lot of external I/O (e.g. HTTP API calls), and uses more memory because each process has a large memory overhead.
</p>
</li>
<li>
<p>
<em>thread</em> - multi-threaded, multi-processed I/O concurrency. Each application process has multiple threads (customizable via <a href="#PassengerThreadCount">PassengerThreadCount</a>). This model provides much better I/O concurrency and uses less memory because threads share memory with each other within the same process. However, using this model may cause compatibility problems if the application is not designed to be thread-safe.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>process</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerThreadCount"></span><h4 data-comment-topic="passengerthreadcount-number--10jl64a" data-anchor="PassengerThreadCount">8.6.9. PassengerThreadCount <number></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 4.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Specifies the number of threads that Phusion Passenger should spawn per application process. This option only has effect if <a href="#PassengerConcurrencyModel">PassengerConcurrencyModel</a> is <em>thread</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>1</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxRequests"></span><h4 data-comment-topic="passengermaxrequests-integer--17qkw9n" data-anchor="PassengerMaxRequests">8.6.10. PassengerMaxRequests <integer></h4>
<div class="paragraph"><p>The maximum number of requests an application process will process. After
serving that many requests, the application process will be shut down and
Phusion Passenger will restart it. A value of 0 means that there is no maximum:
an application process will thus be shut down when its idle timeout has been
reached.</p></div>
<div class="paragraph"><p>This option is useful if your application is leaking memory. By shutting
it down after a certain number of requests, all of its memory is guaranteed
to be freed by the operating system.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/caution.png" alt="Caution">
</td>
<td class="content">
<div class="paragraph"><p>The <a href="#PassengerMaxRequests">PassengerMaxRequests</a> directive should be considered
as a workaround for misbehaving applications. It is advised that you fix the
problem in your application rather than relying on these directives as a
measure to avoid memory leaks.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxRequestTime"></span><h4 data-comment-topic="passengermaxrequesttime-seconds--127v1i2" data-anchor="PassengerMaxRequestTime">8.6.11. PassengerMaxRequestTime <seconds></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>The maximum amount of time, in seconds, that an application process may take
to process a request. If the request takes longer than this amount of time,
then the application process will be forcefully shut down, and possibly
restarted upon the next request. A value of 0 means that there is no time limit.</p></div>
<div class="paragraph"><p>This option is useful for preventing your application from freezing for an
indefinite period of time.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<div class="paragraph">
<div class="title">Example</div>
<p>Suppose that most of your requests are known to finish within 2 seconds.
However, there is one URI, <em>/expensive_computation</em>, which is known to take up
to 10 seconds. You can then configure Phusion Passenger as follows:</p>
</div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.example.com
DocumentRoot /webapps/my_app/public
PassengerMaxRequestTime 2
<Location /expensive_computation>
PassengerMaxRequestTime 10
</Location>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>If a request to <em>/expensive_computation</em> takes more than 10 seconds,
or if a request to any other URI takes more than 2 seconds,
then the corresponding application process will be forced to shutdown.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/caution.png" alt="Caution">
</td>
<td class="content">
<div class="paragraph"><p>The <a href="#PassengerMaxRequestTime">PassengerMaxRequestTime</a> directive should be
considered as a workaround for misbehaving applications. It is advised that you
fix the problem in your application rather than relying on these directives as a
measure to avoid freezing applications.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMemoryLimit"></span><h4 data-comment-topic="passengermemorylimit-integer--18irza1" data-anchor="PassengerMemoryLimit">8.6.12. PassengerMemoryLimit <integer></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>The maximum amount of memory that an application process may use, in megabytes.
Once an application process has surpassed its memory limit, it will process
all the requests currently present in its queue and then shut down.
A value of 0 means that there is no maximum: the application’s memory usage
will not be checked.</p></div>
<div class="paragraph"><p>This option is useful if your application is leaking memory. By shutting
it down, all of its memory is guaranteed to be freed by the operating system.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">
<div class="title">A word about permissions</div>
<div class="paragraph"><p>The <a href="#PassengerMemoryLimit">PassengerMemoryLimit</a> directive uses
<span class="monospaced">ps</span> command to query memory usage information. On Linux, it further
queries <span class="monospaced">/proc</span> to obtain additional memory usage information that’s
not obtainable through <span class="monospaced">ps</span>. You should ensure that the <span class="monospaced">ps</span> works
correctly and that the <span class="monospaced">/proc</span> filesystem is accessible by the
<span class="monospaced">PassengerHelperAgent</span> process.</p></div>
</td>
</tr></table>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/caution.png" alt="Caution">
</td>
<td class="content">
<div class="paragraph"><p>The <a href="#PassengerMaxRequests">PassengerMaxRequests</a> and
<a href="#PassengerMemoryLimit">PassengerMemoryLimit</a> directives should be considered
as workarounds for misbehaving applications. It is advised that you fix the
problem in your application rather than relying on these directives as a
measure to avoid memory leaks.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerstatthrottlerate_lt_integer_gt"></span><h4 data-comment-topic="passengerstatthrottlerate-integer--1dcfda3" data-anchor="_passengerstatthrottlerate_lt_integer_gt">8.6.13. PassengerStatThrottleRate <integer></h4>
<div class="paragraph"><p>By default, Phusion Passenger performs several filesystem checks (or, in
programmers jargon, <em>stat() calls</em>) each time a request is processed:</p></div>
<div class="ulist"><ul>
<li>
<p>
It checks whether <em>config/environment.rb</em>, <em>config.ru</em> or <em>passenger_wsgi.py</em>
is present, in order to autodetect Rails, Rack and WSGI applications.
</p>
</li>
<li>
<p>
It checks whether <em>restart.txt</em> has changed or whether <em>always_restart.txt</em>
exists, in order to determine whether the application should be restarted.
</p>
</li>
</ul></div>
<div class="paragraph"><p>On some systems where disk I/O is expensive, e.g. systems where the harddisk is
already being heavily loaded, or systems where applications are stored on NFS
shares, these filesystem checks can incur a lot of overhead.</p></div>
<div class="paragraph"><p>You can decrease or almost entirely eliminate this overhead by setting
<em>PassengerStatThrottleRate</em>. Setting this option to a value of <em>x</em> means that
the above list of filesystem checks will be performed at most once every <em>x</em>
seconds. Setting it to a value of <em>0</em> means that no throttling will take place,
or in other words, that the above list of filesystem checks will be performed on
every request.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Limits</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>0</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerPreStart"></span><h4 data-comment-topic="passengerprestart-url--1utb57k" data-anchor="PassengerPreStart">8.6.14. PassengerPreStart <url></h4>
<div class="paragraph"><p>By default, Phusion Passenger does not start any application processes until said
web application is first accessed. The result is that the first visitor of said
web application might experience a small delay as Phusion Passenger is starting
the web application on demand. If that is undesirable, then this directive can be
used to pre-started application processes during Apache startup.</p></div>
<div class="paragraph"><p>A few things to be careful of:</p></div>
<div class="ulist"><ul>
<li>
<p>
This directive accepts the <strong>URL</strong> of the web application you want to pre-start,
not a on/off value! This might seem a bit weird, but read on for rationale. As
for the specifics of the URL:
</p>
<div class="ulist"><ul>
<li>
<p>
The domain part of the URL must be equal to the value of the <em>ServerName</em>
directive of the VirtualHost block that defines the web application.
</p>
</li>
<li>
<p>
Unless the web application is deployed on port 80, the URL should contain
the web application’s port number too.
</p>
</li>
<li>
<p>
The path part of the URL must point to some URI that the web application
handles.
</p>
</li>
</ul></div>
</li>
<li>
<p>
You will probably want to combine this option with
<a href="#PassengerMinInstances">PassengerMinInstances</a> because application processes
started with <em>PassengerPreStart</em> are subject to the usual idle timeout rules.
See the example below for an explanation.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified any number of times.</p></div>
<div class="sect4">
<h5 id="_example_1_basic_usage">Example 1: basic usage</h5>
<div class="paragraph"><p>Suppose that you have the following web applications.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName foo.com
DocumentRoot /webapps/foo/public
</VirtualHost>
<VirtualHost *:3500>
ServerName bar.com
DocumentRoot /webapps/bar/public
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>You want both of them to be pre-started during Apache startup. The URL for
foo.com is <em>http://foo.com/</em> (or, equivalently, <em>http://foo.com:80/</em>) and
the URL for bar.com is <em>http://bar.com:3500/</em>. So we add two PassengerPreStart
directives, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName foo.com
DocumentRoot /webapps/foo/public
</VirtualHost>
<VirtualHost *:3500>
ServerName bar.com
DocumentRoot /webapps/bar/public
</VirtualHost>
PassengerPreStart http://foo.com/ # <--- added
PassengerPreStart http://bar.com:3500/ # <--- added</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_example_2_pre_starting_apps_that_are_deployed_in_sub_uris">Example 2: pre-starting apps that are deployed in sub-URIs</h5>
<div class="paragraph"><p>Suppose that you have a web application deployed in a sub-URI <em>/store</em>, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName myblog.com
DocumentRoot /webapps/wordpress
Alias /store /websites/store/public
<Location /store>
PassengerBaseURI /store
PassengerAppRoot /websites/store
</Location>
<Directory /websites/store/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>Then specify the domain name of its containing virtual host followed by the sub-URI,
like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName myblog.com
DocumentRoot /webapps/wordpress
Alias /store /websites/store/public
<Location /store>
PassengerBaseURI /store
PassengerAppRoot /websites/store
</Location>
<Directory /websites/store/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
PassengerPreStart http://myblog.com/store # <----- added</pre>
</div>
</div>
<div class="paragraph"><p>The sub-URI <strong>must</strong> be included; if you don’t then the directive will have no effect.
The following example is wrong and won’t pre-start the store web application:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>PassengerPreStart http://myblog.com/ # <----- WRONG! Missing "/store" part.</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_example_3_combining_with_passengermininstances">Example 3: combining with PassengerMinInstances</h5>
<div class="paragraph"><p>Application processes started with PassengerPreStart are
also subject to the idle timeout rules as specified by
<a href="#PassengerPoolIdleTime">PassengerPoolIdleTime</a>! That means that by default,
the pre-started application processes for foo.com are bar.com are shut down
after a few minutes of inactivity. If you don’t want that to happen, then
you should combine PassengerPreStart with
<a href="#PassengerMinInstances">PassengerMinInstances</a>, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName foo.com
DocumentRoot /webapps/foo/public
# Added!
PassengerMinInstances 1
</VirtualHost>
<VirtualHost *:3500>
ServerName bar.com
DocumentRoot /webapps/bar/public
# Added!
PassengerMinInstances 1
</VirtualHost>
PassengerPreStart http://foo.com/
PassengerPreStart http://bar.com:3500/</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_so_why_a_url_why_not_just_an_on_off_flag">So why a URL? Why not just an on/off flag?</h5>
<div class="paragraph"><p>A directive that accepts a simple on/off flag is definitely more intuitive,
but due technical difficulties w.r.t. the way Apache works, it’s very hard
to implement it like that:</p></div>
<div class="ulist"><ul>
<li>
<p>
It is very hard to obtain a full list of web applications defined in the
Apache configuration file(s). In other words, it’s hard for Phusion Passenger
to know which web applications are deployed on Apache until a web application
is first accessed, and without such a list Phusion Passenger wouldn’t know
which web applications to pre-start. It’s probably not completely impossible
to obtain such a list, but this brings us to the following point;
</p>
</li>
<li>
<p>
Users expect things like <em>mod_env</em> to work even in combination with Phusion
Passenger. For example some people put “SetEnv PATH=….” in their virtual
host block and they expect the web application to pick that environment variable
up when it’s started. Information like this is stored in module-specific
locations that Phusion Passenger cannot access directly. Even if the previous
bullet point is solved and we can obtain a list of web applications,
we cannot start the application with the correct mod_env information.
mod_env is just one such example; there are probably many other Apache modules,
all of which people expect to work, but we cannot answer to those expectations
if PassengerPreStart is implemented as a simple on/off flag.
</p>
</li>
</ul></div>
<div class="paragraph"><p>So as a compromise, we made it accept a URL. This is easier to implement for
us and altough it looks weird, it behaves consistently w.r.t. cooperation
with other Apache modules.</p></div>
</div>
<div class="sect4">
<h5 id="_what_does_phusion_passenger_do_with_the_url">What does Phusion Passenger do with the URL?</h5>
<div class="paragraph"><p>During Apache startup, Phusion Passenger will send a dummy HEAD request to the
given URL and discard the result. In other words, Phusion Passenger simulates a
web access at the given URL. However this simulated request is always sent to
localhost, <strong>not</strong> to the IP that the domain resolves to. Suppose that bar.com
in example 1 resolves to 209.85.227.99; Phusion Passenger will
send the following HTTP request to 127.0.0.1 port 3500 (and not to 209.85.227.99
port 3500):</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>HEAD / HTTP/1.1
Host: bar.com
Connection: close</pre>
</div>
</div>
<div class="paragraph"><p>Similarly, for example 2, Phusion Passenger will send the following HTTP request
to 127.0.0.1 port 80:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>HEAD /store HTTP/1.1
Host: myblog.com
Connection: close</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_do_i_need_to_edit_etc_hosts_and_point_the_domain_in_the_url_to_127_0_0_1">Do I need to edit /etc/hosts and point the domain in the URL to 127.0.0.1?</h5>
<div class="paragraph"><p>No. See previous subsection.</p></div>
</div>
<div class="sect4">
<h5 id="_my_web_application_consists_of_multiple_web_servers_what_url_do_i_need_to_specify_and_in_which_web_server_8217_s_apache_config_file">My web application consists of multiple web servers. What URL do I need to specify, and in which web server’s Apache config file?</h5>
<div class="paragraph"><p>Put the web application’s virtual host’s ServerName value and the virtual host’s
port in the URL, and put
PassengerPreStart on all machines that you want to pre-start the web application
on. The simulated web request is always sent to 127.0.0.1, with the domain name
in the URL as value for the <em>Host</em> HTTP header, so you don’t need to worry about
the request ending up at a different web server in the cluster.</p></div>
</div>
<div class="sect4">
<h5 id="_does_passengerprestart_support_https_urls">Does PassengerPreStart support https:// URLs?</h5>
<div class="paragraph"><p>Yes. And it does not perform any certificate validation.</p></div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerHighPerformance"></span><h4 data-comment-topic="passengerhighperformance-on-off--nvfa86" data-anchor="PassengerHighPerformance">8.6.15. PassengerHighPerformance <on|off></h4>
<div class="paragraph"><p>By default, Phusion Passenger is compatible with mod_rewrite and most other
Apache modules. However, a lot of effort is required in order to be compatible.
If you turn <em>PassengerHighPerformance</em> to <em>on</em>, then Phusion Passenger will be
a little faster, in return for reduced compatibility with other Apache modules.</p></div>
<div class="paragraph"><p>In places where <em>PassengerHighPerformance</em> is turned on, mod_rewrite rules will
likely not work. mod_autoindex (the module which displays a directory index)
will also not work. Other Apache modules may or may not work, depending on what
they exactly do. We recommend you to find out how other modules behave in high
performance mode via testing.</p></div>
<div class="paragraph"><p>This option is <strong>not</strong> an all-or-nothing global option: you can enable high
performance mode for certain virtual hosts or certain URLs only.
The <em>PassengerHighPerformance</em> option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>,
so high performance mode is disabled by default, and you have to explicitly
enable it.</p></div>
<div class="paragraph">
<div class="title">When to enable high performance mode?</div>
<p>If you do not use mod_rewrite or other Apache modules then it might make
sense to enable high performance mode.</p>
</div>
<div class="paragraph"><p>It’s likely that some of your applications depend on mod_rewrite or other
Apache modules, while some do not. In that case you can enable high performance
for only those applications that don’t use other Apache modules. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
.... mod_rewrite rules or options for other Apache modules here ...
</VirtualHost>
<VirtualHost *:80>
ServerName www.bar.com
DocumentRoot /apps/bar/public
PassengerHighPerformance on
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>In the above example, high performance mode is only enabled for www.bar.com.
It is disabled for everything else.</p></div>
<div class="paragraph"><p>If your application generally depends on mod_rewrite or other Apache modules,
but a certain URL that’s accessed often doesn’t depend on those other modules,
then you can enable high performance mode for a certain URL only. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.foo.com
DocumentRoot /apps/foo/public
.... mod_rewrite rules or options for other Apache modules here ...
<Location /chatroom/ajax_update_poll>
PassengerHighPerformance on
</Location>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>This enables high performance mode for
<a href="http://www.foo.com/chatroom/ajax_update_poll">http://www.foo.com/chatroom/ajax_update_poll</a> only.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_connection_handling_options"></span><h3 data-comment-topic="connection-handling-options-1k3zd1a" data-anchor="_connection_handling_options">8.7. Connection handling options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerBufferUpload"></span><h4 data-comment-topic="passengerbufferupload-on-off--1lsjr93" data-anchor="PassengerBufferUpload">8.7.1. PassengerBufferUpload <on|off></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.26.</strong></p></div>
<div class="paragraph"><p>When turned on, HTTP request uploads (HTTP POST request bodies) will be buffered before sending the request to the application. Enabling upload buffering protects the application from slow clients, but will also prevent the ability to track upload progress.</p></div>
<div class="paragraph"><p>If you want to allow your application to track upload progress, it is recommended that you disable upload buffering for specific URIs only. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># Disable upload buffering for /upload_video only.
<Location /upload_video>
PassengerBufferUpload off
</Location></pre>
</div>
</div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>on</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerBufferResponse"></span><h4 data-comment-topic="passengerbufferresponse-on-off--1y7ilka" data-anchor="PassengerBufferResponse">8.7.2. PassengerBufferResponse <on|off></h4>
<div class="paragraph"><p>When turned on, application-generated responses are buffered by Apache. Buffering will
happen in memory.</p></div>
<div class="paragraph"><p>Before we proceed with explaining this configuration option, we want to state the following to avoid confusion. If you use Phusion Passenger for Apache, there are in fact two response buffering systems active:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
The Apache response buffering system. <span class="monospaced">PassengerBufferResponse</span> turns this on or off.
</p>
</li>
<li>
<p>
The Phusion Passenger response buffering system, a.k.a. <em>real-time disk-backed response buffering</em>. This buffering system is always on, regardless of the value of <span class="monospaced">PassengerBufferResponse</span>.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Response buffering is useful because it protects against slow HTTP clients that do not read responses immediately or quickly enough. Buffering prevents such slow clients from blocking web applications that have limited concurrency. Because Phusion Passenger’s response buffering is always turned on, you are always protected. Therefore, <span class="monospaced">PassengerBufferResponse</span> is off by default, and you never should have to turn it on.</p></div>
<div class="paragraph"><p>If for whatever reason you want to turn Apache-level response buffering on, you can do so with this option.</p></div>
<div class="paragraph"><p>Apache’s response buffering works differently from Phusion Passenger’s. Apache’s buffering system buffers the entire response before attempting to send it to the client, while Phusion Passenger’s attempts to send the data to the client immediately. Therefore, if you turn on <span class="monospaced">PassengerBufferResponse</span>, you may interfere with applications that want to stream responses to the client.
Apache’s version also buffers to memory only, making it problematic for large responses. Phusion Passenger’s version buffers to disk when the response exceeds a certain threshold.</p></div>
<div class="paragraph"><p>How does response buffering - whether it’s done by Apache or by Phusion Passenger - exactly protect against slow clients?
Consider an HTTP client that’s on a dial-up modem link, and your
application process generates a 2 MB response. If the response is buffered
then your application process will be blocked until the entire 2 MB has been
sent out to the HTTP client. This disallows your application process to do any useful
work in the mean time. By buffering responses, Phusion Passenger or Apache will read
the application response as quickly as possible and will take care of forwarding the data
to slow clients.</p></div>
<div class="paragraph"><p>So keep in mind that enabling <span class="monospaced">passenger_buffering_response</span> will make streaming responses
impossible. Consider for example this piece of Rails code:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>render :text => lambda { |response, output|
10.times do |i|
output.write("entry #{i}\n")
output.flush
sleep 1
end
}</pre>
</div>
</div>
<div class="paragraph"><p>…or this piece of Rack code:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>class Response
def each
10.times do |i|
yield("entry #{i}\n")
sleep 1
end
end
end
app = lambda do |env|
[200, { "Content-Type" => "text/plain" }, Response.new]
end</pre>
</div>
</div>
<div class="paragraph"><p>When <span class="monospaced">PassengerBufferResponse</span> is turned on, Apache will wait until
the application is done sending the entire response before forwarding it
to the client. The client will not receive anything for 10 seconds,
after which it receives the entire response at once.
When <span class="monospaced">PassengerBufferResponse</span> is turned off, it works as expected: the client
receives an "entry X" message every second for 10 seconds.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">
<div class="paragraph"><p>The <a href="#PassengerBufferResponse">PassengerBufferResponse</a> directive should be turned off
if responses can be huge. Because entire responses are buffered in memory when turned on.</p></div>
</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerErrorOverride"></span><h4 data-comment-topic="passengererroroverride-on-off--1pq9nez" data-anchor="PassengerErrorOverride">8.7.3. PassengerErrorOverride <on|off></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.24.</strong></p></div>
<div class="paragraph"><p>Decides whether Apache will intercept and handle responses with HTTP status codes of 400 and higher. This directive is useful where you want to have a common look and feel on the error pages seen by the end user. This also allows for included files (via mod_include’s SSI) to get the error code and act accordingly (default behavior would display the error page of the proxied server, turning this on shows the SSI Error message).</p></div>
<div class="paragraph"><p>This directive does not affect the processing of informational (1xx), normal success (2xx), or redirect (3xx) responses.</p></div>
<div class="paragraph"><p>By default, all responses are sent as-is from the application or from the Phusion Passenger core. If you turn this option on then Apache will be able to handle such responses using the Apache <span class="monospaced">ErrorDocument</span> option.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerMaxRequestQueueSize"></span><h4 data-comment-topic="passenger-max-request-queue-size-number--1f1uocd" data-anchor="PassengerMaxRequestQueueSize">8.7.4. PassengerMaxRequestQueueSize <number></h4>
<div class="paragraph"><p><strong>Introduced in version 4.0.15.</strong></p></div>
<div class="paragraph"><p>When all application processes are already handling their maximum number of concurrent requests, Phusion Passenger will queue all incoming requests. This option specifies the maximum size for that queue. If the queue is already at this specified limit, then Phusion Passenger will immediately send a "503 Service Unavailable" error to any incoming requests.</p></div>
<div class="paragraph"><p>A value of 0 means that the queue is unbounded.</p></div>
<div class="paragraph"><p><a href="http://stackoverflow.com/questions/20402801/what-is-optimal-value-for-phusion-passenger-passengermaxrequestqueuesize">This article on StackOverflow</a> explains how the request queue works, what it means for the queue to grow or become full, why that is bad, and what you can do about it.</p></div>
<div class="paragraph"><p>You may combine this option with <a href="#PassengerErrorOverride">PassengerErrorOverride</a> and <span class="monospaced">ErrorDocument</span> to set a custom error page whenever the queue is full. In the following example, Apache will serve /error503.html whenever the queue is full:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>PassengerErrorOverride on
ErrorDocument 504 /error504.html</pre>
</div>
</div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>100</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_compatibility_options"></span><h3 data-comment-topic="compatibility-options-8jve5a" data-anchor="_compatibility_options">8.8. Compatibility options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerResolveSymlinksInDocumentRoot"></span><h4 data-comment-topic="passengerresolvesymlinksindocumentroot-on-off--1r0qcp8" data-anchor="PassengerResolveSymlinksInDocumentRoot">8.8.1. PassengerResolveSymlinksInDocumentRoot <on|off></h4>
<div class="paragraph"><p>Configures whether Phusion Passenger should resolve symlinks in the document root.
Please refer to <a href="#application_detection">How Phusion Passenger detects whether a virtual host is a web application</a> for more information.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. It is off by default.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerallowencodedslashes_lt_on_off_gt"></span><h4 data-comment-topic="passengerallowencodedslashes-on-off--1y3s1ww" data-anchor="_passengerallowencodedslashes_lt_on_off_gt">8.8.2. PassengerAllowEncodedSlashes <on|off></h4>
<div class="paragraph"><p>By default, Apache doesn’t support URLs with encoded slashes (%2f), e.g. URLs like
this: <span class="monospaced">/users/fujikura%2fyuu</span>. If you access such an URL then Apache will return a
404 Not Found error. This can be solved by turning on PassengerAllowEncodedSlashes
as well as Apache’s
<a href="http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes">AllowEncodedSlashes</a>.</p></div>
<div class="paragraph"><p>Is it important that you turn on both AllowEncodedSlashes <strong>and</strong> PassengerAllowEncodedSlashes,
otherwise this feature will not work properly.</p></div>
<div class="paragraph"><p>PassengerAllowEncodedSlashes may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. It is off by default.</p></div>
<div class="paragraph"><p>Please note however that turning on support for encoded slashes will break support for
mod_rewrite passthrough rules. Because of bugs/limitations in Apache, Phusion Passenger
can support either encoded slashes or mod_rewrite passthrough rules, but not both at the
same time. Luckily this option can be specified anywhere, so you can enable it only for
virtual hosts or URLs that need it:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><VirtualHost *:80>
ServerName www.example.com
DocumentRoot /webapps/example/public
AllowEncodedSlashes on
RewriteEngine on
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Make /about an alias for /info/about.
RewriteRule ^/about$ /info/about [PT,L]
<Location ~ "^/users/">
# In a location block so that it doesn't interfere with the
# above /about mod_rewrite rule.
PassengerAllowEncodedSlashes on
</Location>
</VirtualHost></pre>
</div>
</div>
<div class="paragraph"><p>With this, <a href="http://www.example.com/users/fujikura%2fyuu">http://www.example.com/users/fujikura%2fyuu</a> will work properly, and
accessing <a href="http://www.example.com/about">http://www.example.com/about</a> will properly display the result of
<a href="http://www.example.com/info/about">http://www.example.com/info/about</a>. Notice that PassengerAllowEncodedSlashes only
interferes with passthrough rules, not with any other mod_rewrite rules. The rules for
displaying maintenance.html will work fine even for URLs starting with "/users".</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_logging_and_debugging_options"></span><h3 data-comment-topic="logging-and-debugging-options-el2cuc" data-anchor="_logging_and_debugging_options">8.9. Logging and debugging options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerLogLevel"></span><h4 data-comment-topic="passengerloglevel-integer--s3kbil" data-anchor="PassengerLogLevel">8.9.1. PassengerLogLevel <integer></h4>
<div class="paragraph"><p>This option allows one to specify how much information Phusion Passenger should
write to the Apache error log file. A higher log level value means that more
information will be logged.</p></div>
<div class="paragraph"><p>Possible values are:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>0</em>: Show only errors and warnings.
</p>
</li>
<li>
<p>
<em>1</em>: Show the most important debugging information. This might be useful for
system administrators who are trying to figure out the cause of a
problem.
</p>
</li>
<li>
<p>
<em>2</em>: Show more debugging information. This is typically only useful for developers.
</p>
</li>
<li>
<p>
<em>3</em>: Show even more debugging information.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.
The default is <em>0</em>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerdebuglogfile_lt_filename_gt"></span><h4 data-comment-topic="passengerdebuglogfile-filename--1wjm2j1" data-anchor="_passengerdebuglogfile_lt_filename_gt">8.9.2. PassengerDebugLogFile <filename></h4>
<div class="paragraph"><p>By default Phusion Passenger debugging and error messages are written to the global
web server error log. This option allows one to specify the file that debugging and
error messages should be written to instead.</p></div>
<div class="paragraph"><p>This option may only occur once, in the global server configuration.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_passengerdebugger_lt_on_off_gt"></span><h4 data-comment-topic="passengerdebugger-on-off--19you7e" data-anchor="_passengerdebugger_lt_on_off_gt">8.9.3. PassengerDebugger <on|off></h4>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Turns support for application debugging on or off. In case of Ruby applications,
turning this option on will cause them to load the <span class="monospaced">ruby-debug</span> gem (when on Ruby 1.8),
the <span class="monospaced">debugger</span> gem (when on Ruby 1.9) or the <span class="monospaced">byebug</span> gem (when on Ruby 2.0). If you’re
using Bundler, you should add this to your Gemfile:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem 'ruby-debug', :platforms => :ruby_18
gem 'debugger', :platforms => :ruby_19
gem 'byebug', :platforms => :ruby_20</pre>
</div>
</div>
<div class="paragraph"><p>Once debugging is turned on, you can use the command <span class="monospaced">passenger-irb --debug <PID></span> to attach an rdebug console to the application process with the given PID. Attaching will succeed once the application process executes a <span class="monospaced">debugger</span> command.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverride Options</span> is on.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_advanced_options"></span><h3 data-comment-topic="advanced-options-1ab1jkq" data-anchor="_advanced_options">8.10. Advanced options</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerTempDir"></span><h4 data-comment-topic="passengertempdir-directory--68h2ng" data-anchor="PassengerTempDir">8.10.1. PassengerTempDir <directory></h4>
<div class="paragraph"><p>Specifies the directory that Phusion Passenger should use for storing temporary
files. This includes things such as Unix socket files, buffered file uploads
(see also <a href="#PassengerUploadBufferDir">PassengerUploadBufferDir</a>), etc.</p></div>
<div class="paragraph"><p>This option may be specified once, in the global server configuration. The
default temp directory that Phusion Passenger uses is <em>/tmp</em>.</p></div>
<div class="paragraph"><p>This option is especially useful if Apache is not allowed to write to /tmp
(which is the case on some systems with strict SELinux policies) or if the
partition that /tmp lives on doesn’t have enough disk space.</p></div>
<div class="paragraph">
<div class="title">Command line tools</div>
<p>Some Phusion Passenger command line administration tools, such as
<span class="monospaced">passenger-status</span>, must know what Phusion Passenger’s temp directory is
in order to function properly. You can pass the directory through the
<span class="monospaced">PASSENGER_TMPDIR</span> environment variable, or the <span class="monospaced">TMPDIR</span> environment variable
(the former will be used if both are specified).</p>
</div>
<div class="paragraph"><p>For example, if you set <em>PassengerTempDir</em> to <em>/my_temp_dir</em>, then invoke
<span class="monospaced">passenger-status</span> after you’ve set the <span class="monospaced">PASSENGER_TMPDIR</span> or <span class="monospaced">TMPDIR</span>
environment variable, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>export PASSENGER_TMPDIR=/my_temp-dir
sudo -E passenger-status
# The -E option tells 'sudo' to preserve environment variables.</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="PassengerUploadBufferDir"></span><h4 data-comment-topic="passengeruploadbufferdir-directory--kdr8at" data-anchor="PassengerUploadBufferDir">8.10.2. PassengerUploadBufferDir <directory></h4>
<div class="paragraph"><p>Phusion Passenger buffers large file uploads to disk in order prevent slow file
uploads from blocking web applications. By default, a subdirectory in the
system’s temporary files directory (or a subdirectory in the directory specified
in <a href="#PassengerTempDir">PassengerTempDir</a>, if set) is automatically created for
storing these buffered file uploads.</p></div>
<div class="paragraph"><p>This configuration directive allows you to specify a different directory for storing
buffered file uploads. If you’ve specified such a directory (as opposed to using
Phusion Passenger’s default) then you <strong>must</strong> ensure that this directory exists.</p></div>
<div class="paragraph"><p>This configuration directive is also useful if you’re using apache2-mpm-itk.
The buffered file upload directory that Phusion Passenger creates by default has
very strict permissions: it can only be accessed by the Apache worker processes.
However, Phusion Passenger assumes that all Apache worker processes are running
as the same user. apache2-mpm-itk breaks this assumption by running multiple
Apache worker processes as different users. So if you’re using apace2-mpm-itk,
you should set this option to a directory that is writable by all Apache worker
processes, such as <em>/tmp</em>.</p></div>
<div class="paragraph"><p>You may specify <em>PassengerUploadBufferDir</em> in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the global server configuration.
</p>
</li>
<li>
<p>
In a virtual host configuration block.
</p>
</li>
<li>
<p>
In a <span class="monospaced"><Directory></span> or <span class="monospaced"><Location></span> block.
</p>
</li>
<li>
<p>
In <em>.htaccess</em>, if <span class="monospaced">AllowOverrides Options</span> is enabled.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_deprecated_or_removed_options"></span><h3 data-comment-topic="deprecated-options-pm9m57" data-anchor="_deprecated_or_removed_options">8.11. Deprecated or removed options</h3>
<div class="paragraph"><p>The following options have been deprecated, but are still supported for backwards
compatibility reasons.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsruby"></span><h4 data-comment-topic="railsruby-ht09ei" data-anchor="_railsruby">8.11.1. RailsRuby</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerRuby">PassengerRuby</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsbaseuri_and_rackbaseuri"></span><h4 data-comment-topic="railsbaseuri-uri--1txrw3k" data-anchor="_railsbaseuri_and_rackbaseuri">8.11.2. RailsBaseURI and RackBaseURI</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerBaseURI">PassengerBaseURI</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsuserswitching"></span><h4 data-comment-topic="railsuserswitching-1npx8y4" data-anchor="_railsuserswitching">8.11.3. RailsUserSwitching</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerUserSwitching">PassengerUserSwitching</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsdefaultuser"></span><h4 data-comment-topic="railsdefaultuser-19j7n3m" data-anchor="_railsdefaultuser">8.11.4. RailsDefaultUser</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerDefaultUser">PassengerDefaultUser</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsallowmodrewrite"></span><h4 data-comment-topic="railsallowmodrewrite-1vkziro" data-anchor="_railsallowmodrewrite">8.11.5. RailsAllowModRewrite</h4>
<div class="paragraph"><p>This option doesn’t do anything anymore in recent versions of Phusion Passenger.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsspawnmethod"></span><h4 data-comment-topic="railsspawnmethod-1aljgpa" data-anchor="_railsspawnmethod">8.11.6. RailsSpawnMethod</h4>
<div class="paragraph"><p>Deprecated in favor of <a href="#PassengerSpawnMethod">PassengerSpawnMethod</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsautodetect_rackautodetect_and_wsgiautodetect"></span><h4 data-comment-topic="railsautodetect-rackautodetect-and-wsgiautodetect-1qgakzs" data-anchor="_railsautodetect_rackautodetect_and_wsgiautodetect">8.11.7. RailsAutoDetect, RackAutoDetect and WsgiAutoDetect</h4>
<div class="paragraph"><p>These options have been removed in version 4.0.0 as part of an optimization. You should use <a href="#PassengerEnabled">PassengerEnabled</a> instead.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsappspawneridletime"></span><h4 data-comment-topic="railsappspawneridletime-heh41r" data-anchor="_railsappspawneridletime">8.11.8. RailsAppSpawnerIdleTime</h4>
<div class="paragraph"><p>This option has been removed in version 4.0.0, and replaced with <a href="#PassengerMaxPreloaderIdleTime">PassengerMaxPreloaderIdleTime</a>.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_railsframeworkspawneridletime"></span><h4 data-comment-topic="railsframeworkspawneridletime-adcf9k" data-anchor="_railsframeworkspawneridletime">8.11.9. RailsFrameworkSpawnerIdleTime</h4>
<div class="paragraph"><p>This option is no longer available in version 4.0.0. There is no alternative because framework spawning has been removed altogether. You should use smart spawning instead.</p></div>
</div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="troubleshooting"></span><h2 data-comment-topic="troubleshooting-2ihihi" data-anchor="troubleshooting">9. Troubleshooting</h2>
<div class="sectionbody">
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_generic_troubleshooting_tips"></span><h3 data-comment-topic="generic-troubleshooting-tips-130iuhe" data-anchor="_generic_troubleshooting_tips">9.1. Generic troubleshooting tips</h3>
<div class="paragraph"><p>One of the first things you should do upon encountering a problem, is to check
the <strong>global</strong> (not the per-vhost) Apache error log file. This is typically located in <span class="monospaced">/var/log/apache2/error_log</span>. You can find out the exact location of the error log by running <span class="monospaced">passenger-config --detect-apache2</span>.
This log file contains:</p></div>
<div class="ulist"><ul>
<li>
<p>
Phusion Passenger error messages.
</p>
</li>
<li>
<p>
Everything that the application writes to STDERR. This typically consists of errors that the application encounters during startup, but not errors that it encounters when it’s handling requests.
</p>
</li>
</ul></div>
<div class="paragraph"><p>If you’re using Ruby on Rails, then you should also check out <span class="monospaced">log/development.log</span> and <span class="monospaced">log/production.log</span>. When an error occurs during request handling, it is typically logged here. This file does <strong>not</strong> contain errors that Rails encounters during startup.</p></div>
<div class="paragraph"><p>Finally, you should be aware that Phusion Passenger runs your application under the <em>production</em> environment by default, not <em>development</em>. You can change this using the
<a href="#RailsEnv">RailsEnv</a>
option.</p></div>
<div class="paragraph"><p>If neither the logs nor this troubleshooting guide can help you, then please check out our <a href="#where_to_get_support">support resources</a>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_why_does_the_first_request_take_a_long_time"></span><h3 data-comment-topic="why-does-the-first-request-take-a-long-time--12mg452" data-anchor="_why_does_the_first_request_take_a_long_time">9.2. Why does the first request take a long time?</h3>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Symptoms</strong>
</dt>
<dd>
<p>
The first request to your application takes more time than usual. Subsequent requests have the normal speed.
</p>
</dd>
<dt class="hdlist1">
<strong>Cause</strong>
</dt>
<dd>
<p>
Phusion Passenger starts your application the first time it is accessed, not during web server startup. Some applications can take several seconds to start. If you’re using Ruby on Rails, then needing 10 seconds to start your application is normal. On slow or heavily loaded servers, or in case of large and heavy applications, the startup time may be even longer.
</p>
</dd>
<dt class="hdlist1">
<strong>Solution</strong>
</dt>
<dd>
<p>
Use the
<a href="#PassengerPreStart">PassengerPreStart</a>
configuration option.
</p>
</dd>
</dl></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_os_x_the_installer_cannot_locate_mamp_8217_s_apache"></span><h3 data-comment-topic="macos-x-the-installer-cannot-locate-mamp-s-apache-or908n" data-anchor="_os_x_the_installer_cannot_locate_mamp_8217_s_apache">9.3. OS X: The installer cannot locate MAMP’s Apache</h3>
<div class="dlist"><dl>
<dt class="hdlist1">
<strong>Symptoms</strong>
</dt>
<dd>
<p>
The installer finds Apache 2 development headers at <span class="monospaced">/Applications/MAMP/Library/bin/apxs</span>. However, Apache cannot be found. The installer also outputs the following error:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>cannot open /Applications/MAMP/Library/build/config_vars.mk:
No such file or directory at /Applications/MAMP/Library/bin/apxs line 218.</pre>
</div>
</div>
</dd>
<dt class="hdlist1">
<strong>Cause</strong>
</dt>
<dd>
<p>
Your MAMP installation seems to be broken. In particular, <em>config_vars.mk</em> is missing.
</p>
</dd>
<dt class="hdlist1">
<strong>Solution</strong>
</dt>
<dd>
<p>
Please read <a href="http://forum.mamp.info/viewtopic.php?t=1866">this forum topic</a> to learn how to fix this problem. See also <a href="http://code.google.com/p/phusion-passenger/issues/detail?id=12">this bug report</a>.
</p>
</dd>
</dl></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_apache_reports_a_403_forbidden_error"></span><h3 data-comment-topic="apache-reports-a-403-forbidden-error-140tb4p" data-anchor="_apache_reports_a_403_forbidden_error">9.4. Apache reports a "403 Forbidden" error</h3>
<div class="paragraph"><p>See next subsection.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_static_assets_such_as_images_and_stylesheets_aren_8217_t_being_displayed"></span><h3 data-comment-topic="static-assets-such-as-images-and-stylesheets-aren-t-being-displayed-uaptpi" data-anchor="_static_assets_such_as_images_and_stylesheets_aren_8217_t_being_displayed">9.5. Static assets such as images and stylesheets aren’t being displayed</h3>
<div class="paragraph"><p>Static assets are accelerated, i.e. they are served directly by Apache and do not
go through the Rails stack. There are two reasons why Apache doesn’t serve static
assets correctly:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Your Apache configuration is too strict, and does not allow HTTP clients to
access static assets. This can be achieved with an <span class="monospaced">Allow from all</span> directive
in the correct place. For example:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre><Directory "/webapps/mycook/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory></pre>
</div>
</div>
<div class="paragraph"><p>See also <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/9699a639a87f85f4/b9d71a03bf2670a5">this discussion</a>.</p></div>
</li>
<li>
<p>
The Apache process doesn’t have permission to access your Rails application’s folder.
Please make sure that the Rails application’s folder, as well as all of its parent folders,
have the correct permissions and/or ownerships.
</p>
</li>
</ol></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_apache_error_log_says_that_the_spawn_manager_script_does_not_exist_or_that_it_does_not_have_permission_to_execute_it"></span><h3 data-comment-topic="the-apache-error-log-says-that-the-spawn-manager-script-does-not-exist-or-that-it-does-not-have-permission-to-execute-it-1fmoozk" data-anchor="_the_apache_error_log_says_that_the_spawn_manager_script_does_not_exist_or_that_it_does_not_have_permission_to_execute_it">9.6. The Apache error log says that the spawn manager script does not exist, or that it does not have permission to execute it</h3>
<div class="paragraph"><p>If you are sure that the <em>PassengerRoot</em> configuration option is set correctly,
then this problem is most likely caused by the fact that you’re running Apache
with SELinux. On Fedora, CentOS and RedHat Enterprise Linux, Apache is locked
down by SELinux policies.</p></div>
<div class="paragraph"><p>To solve this problem, you must set some permissions on the Phusion Passenger files
and folders, so that Apache can access them.</p></div>
<div class="ulist"><ul>
<li>
<p>
If you’ve installed Phusion Passenger via a gem, then run this command to determine
Phusion Passenger’s root folder:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>passenger-config --root</pre>
</div>
</div>
<div class="paragraph"><p>Next, run the following command:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>chcon -R -h -t httpd_sys_content_t /path-to-passenger-root</pre>
</div>
</div>
<div class="paragraph"><p>where <em>/path-to-passenger-root</em> should be replaced with whatever
<span class="monospaced">passenger-config --root</span> printed.</p></div>
</li>
<li>
<p>
If you’ve installed Phusion Passenger via the source tarball, then run the following
command:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>chcon -R -h -t httpd_sys_content_t /path/to/passenger/folder</pre>
</div>
</div>
</li>
</ul></div>
<div class="paragraph"><p>Once the permissions are fixed, restart Apache.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_application_thinks_its_not_on_ssl_even_though_it_is"></span><h3 data-comment-topic="the-application-thinks-its-not-on-ssl-even-though-it-is-u9fcp1" data-anchor="_the_application_thinks_its_not_on_ssl_even_though_it_is">9.7. The application thinks its not on SSL even though it is</h3>
<div class="paragraph"><p>Rails and many other frameworks infers whether it’s running on SSL through the CGI
environment variable <span class="monospaced">HTTPS</span>. Apache always sets this variable when on SSL,
except when SSL is incorrectly configured.</p></div>
<div class="paragraph"><p>Most Apache installations already configure SSL by default on port 443
(conf/extra/httpd-ssl.conf). Some people think they can save some typing in
subsequent SSL vhost blocks, and omit important options like <em>SSLEngine on</em>,
like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># httpd-ssl.conf contains something like:
# <VirtualHost _default_:443>
# SSLEngine on
# ...
# </VirtualHost>
Include conf/extra/httpd-ssl.conf
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /webapps/example/public
</Virtualhost></pre>
</div>
</div>
<div class="paragraph"><p><strong>This is wrong!</strong> In each SSL vhost block you must re-specify all the SSL options.
Otherwise Apache won’t properly detect the vhost as an SSL vhost block. Here’s
the corrected example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Include conf/extra/httpd-ssl.conf
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /webapps/example/public
SSLEngine on
...more SSL options here...
</Virtualhost></pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_ruby_on_rails_specific_troubleshooting"></span><h3 data-comment-topic="ruby-on-rails-specific-problems-6umss5" data-anchor="_ruby_on_rails_specific_troubleshooting">9.8. Ruby on Rails-specific troubleshooting</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_about_your_application_8217_s_environment_link_does_not_work"></span><h4 data-comment-topic="the-about-your-application-s-environment-link-does-not-work-7k4tlm" data-anchor="_the_about_your_application_8217_s_environment_link_does_not_work">9.8.1. The "About your application’s environment" link does not work</h4>
<div class="paragraph"><p>The "About your application’s environment" link only works if the application is started in the <em>development</em> environment. Phusion Passenger starts the application in the <em>production</em> environment by default. Please use
<a href="#RailsEnv">RailsEnv</a>
to change it.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error"></span><h4 data-comment-topic="the-rails-application-reports-that-it-s-unable-to-start-because-of-a-permission-error-v53i6s" data-anchor="_the_rails_application_reports_that_it_8217_s_unable_to_start_because_of_a_permission_error">9.8.2. The Rails application reports that it’s unable to start because of a permission error</h4>
<div class="paragraph"><p>Please check whether your Rails application’s folder has the correct
permissions. By default, Rails applications are started as the owner of the
file <span class="monospaced">config.ru</span>, except if the file is owned by root. If the
file is owned by root, then the Rails application will be started as <em>nobody</em>
(or as the user specify by <a href="#RailsDefaultUser">RailsDefaultUser</a>, if that’s
specified).</p></div>
<div class="paragraph"><p>Please read <a href="#user_switching">User switching (security)</a> for details.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_rails_application_8217_s_log_file_is_not_being_written_to"></span><h4 data-comment-topic="my-rails-application-s-log-file-is-not-being-written-to-3i747l" data-anchor="_the_rails_application_8217_s_log_file_is_not_being_written_to">9.8.3. The Rails application’s log file is not being written to</h4>
<div class="paragraph"><p>There are a couple things that you should be aware of:</p></div>
<div class="ulist"><ul>
<li>
<p>
By default, Phusion Passenger runs Rails applications in <em>production</em> mode,
so please be sure to check <span class="monospaced">production.log</span> instead of <span class="monospaced">development.log</span>.
</p>
<div class="paragraph"><p>See
<a href="#RailsEnv">RailsEnv</a>
for configuration.
- By default, Phusion Passenger runs Rails applications as the owner of <span class="monospaced">config.ru</span>.
So the log file can only be written to if that user has write permission to the
log file. Please <span class="monospaced">chmod</span> or <span class="monospaced">chown</span> your log file accordingly.</p></div>
<div class="paragraph"><p>See <a href="#User_switching">User switching (security)</a> for details.</p></div>
</li>
</ul></div>
<div class="paragraph"><p>If you’re using a RedHat-derived Linux distribution (such as Fedora or CentOS)
then it is <a href="http://code.google.com/p/phusion-passenger/issues/detail?id=4">possible
that SELinux is interfering</a>. RedHat’s SELinux policy only allows Apache to read/write
directories that have the <em>httpd_sys_content_t</em> security context. Please run the
following command to give your Rails application folder that context:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>chcon -R -h -t httpd_sys_content_t /path/to/your/rails/app</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="conflicting_apache_modules"></span><h3 data-comment-topic="conflicting-apache-modules-1uwpixk" data-anchor="conflicting_apache_modules">9.9. Conflicting Apache modules</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_mod_userdir"></span><h4 data-comment-topic="mod-userdir-x5e2te" data-anchor="_mod_userdir">9.9.1. mod_userdir</h4>
<div class="paragraph"><p><em>mod_userdir</em> is not compatible with Phusion Passenger at the moment.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_multiviews_mod_negotiation"></span><h4 data-comment-topic="multiviews-mod-negotiation--zchfg0" data-anchor="_multiviews_mod_negotiation">9.9.2. MultiViews (mod_negotiation)</h4>
<div class="paragraph"><p>MultiViews is not compatible with Phusion Passenger. You should disable MultiViews
for all Phusion Passenger hosts.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_virtualdocumentroot"></span><h4 data-comment-topic="virtualdocumentroot-14cwd7l" data-anchor="_virtualdocumentroot">9.9.3. VirtualDocumentRoot</h4>
<div class="paragraph"><p>VirtualDocumentRoot is not compatible with Phusion Passenger at the moment.</p></div>
</div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_analysis_and_system_maintenance"></span><h2 data-comment-topic="analysis-and-system-maintenance-qvkwzr" data-anchor="_analysis_and_system_maintenance">10. Analysis and system maintenance</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger provides a set of tools, which are useful for system analysis,
maintenance and troubleshooting.</p></div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_inspecting_memory_usage"></span><h3 data-comment-topic="inspecting-memory-usage-1bkis6i" data-anchor="_inspecting_memory_usage">10.1. Inspecting memory usage</h3>
<div class="paragraph"><p>Process inspection tools such as <span class="monospaced">ps</span> and <span class="monospaced">top</span> are useful, but they
<a href="http://groups.google.com/group/phusion-passenger/msg/1fd1c233456d3180">rarely show the correct memory usage</a>.
The real memory usage is usually lower than what <span class="monospaced">ps</span> and <span class="monospaced">top</span> report.</p></div>
<div class="paragraph"><p>There are many technical reasons why this is so, but an explanation is beyond
the scope of this Users Guide. We kindly refer the interested reader to
operating systems literature about <em>virtual memory</em> and <em>copy-on-write</em>.</p></div>
<div class="paragraph"><p>The tool <span class="monospaced">passenger-memory-stats</span> allows one to easily analyze Phusion Passenger’s
and the web server’s real memory usage. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[bash@localhost root]# passenger-memory-stats
------------- Apache processes --------------.
PID PPID Threads VMSize Private Name
---------------------------------------------.
5947 1 9 90.6 MB 0.5 MB /usr/sbin/apache2 -k start
5948 5947 1 18.9 MB 0.7 MB /usr/sbin/fcgi-pm -k start
6029 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6030 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6031 5947 1 42.5 MB 0.3 MB /usr/sbin/apache2 -k start
6033 5947 1 42.5 MB 0.4 MB /usr/sbin/apache2 -k start
6034 5947 1 50.5 MB 0.4 MB /usr/sbin/apache2 -k start
23482 5947 1 82.6 MB 0.4 MB /usr/sbin/apache2 -k start
### Processes: 8
### Total private dirty RSS: 3.50 MB
----------- Nginx processes ------------.
PID PPID VMSize Resident Name
----------------------------------------.
51766 51764 82.7 MB 3.9 MB nginx: master process ./objs/nginx
51773 51766 82.9 MB 0.9 MB nginx: worker process
--------- Passenger processes ---------.
PID Threads VMSize Private Name
---------------------------------------.
6026 1 10.9 MB 4.7 MB Passenger spawn server
23481 1 26.7 MB 3.0 MB Passenger FrameworkSpawner: 2.0.2
23791 1 26.8 MB 2.9 MB Passenger ApplicationSpawner: /var/www/projects/app1-foobar
23793 1 26.9 MB 17.1 MB Rails: /var/www/projects/app1-foobar
### Processes: 4
### Total private dirty RSS: 27.76 M</pre>
</div>
</div>
<div class="paragraph"><p>The <em>Private</em> or <em>private dirty RSS</em> field shows the <strong>real</strong> memory usage of processes. Here,
we see that all the Apache and Nginx worker processes only take less than 1 MB memory each.
This is a lot less than the 50-80 MB-ish memory usage as shown in the <em>VMSize</em> column
(which is what a lot of people think is the real memory usage, but is actually not).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">Private dirty RSS reporting only works on Linux. Unfortunately other operating systems
don’t provide facilities for determining processes' private dirty RSS. On non-Linux systems,
the Resident Set Size is reported instead.</td>
</tr></table>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_inspecting_phusion_passenger_8217_s_internal_status"></span><h3 data-comment-topic="inspecting-phusion-passenger-s-internal-status-ukekf7" data-anchor="_inspecting_phusion_passenger_8217_s_internal_status">10.2. Inspecting Phusion Passenger’s internal status</h3>
<div class="paragraph"><p>One can inspect Phusion Passenger’s internal status with the tool <span class="monospaced">passenger-status</span>.
This tool must typically be run as root. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[bash@localhost root]# passenger-status
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
----------- Domains -----------
/var/www/projects/app1-foobar:
PID: 9617 Sessions: 0 Processed: 7 Uptime: 2m 23s</pre>
</div>
</div>
<div class="paragraph"><p>The <em>general information</em> section shows the following information:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
max
</dt>
<dd>
<p>
The maximum number of application instances that Phusion Passenger will
spawn. This equals the value given for <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a> (Apache)
or <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a> (Nginx).
</p>
</dd>
<dt class="hdlist1">
count
</dt>
<dd>
<p>
The number of application instances that are currently alive. This value
is always less than or equal to <em>max</em>.
</p>
</dd>
<dt class="hdlist1">
active
</dt>
<dd>
<p>
The number of application instances that are currently processing
requests. This value is always less than or equal to <em>count</em>.
</p>
</dd>
<dt class="hdlist1">
inactive
</dt>
<dd>
<p>
The number of application instances that are currently <strong>not</strong> processing
requests, i.e. are idle. Idle application instances will be shutdown after a while,
as can be specified with <a href="#PassengerPoolIdleTime">PassengerPoolIdleTime (Apache)</a>/<a href="#PassengerPoolIdleTime">passenger_pool_idle_time (Nginx)</a> (unless this
value is set to 0, in which case application instances are never shut down via idle
time). The value of <em>inactive</em> equals <span class="monospaced">count - active</span>.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>The <em>domains</em> section shows, for each application directory, information about running
application instances:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Sessions
</dt>
<dd>
<p>
Shows how many HTTP client are currently in the queue of that application
Instance, waiting to be processed.
</p>
</dd>
<dt class="hdlist1">
Processed
</dt>
<dd>
<p>
Indicates how many requests the instance has served until now. <strong>Tip:</strong> it’s
possible to limit this number with the <a href="#PassengerMaxRequests">PassengerMaxRequests</a>
configuration directive.
</p>
</dd>
<dt class="hdlist1">
Uptime
</dt>
<dd>
<p>
Shows for how long the application instance has been running.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>Since Phusion Passenger uses fair load balancing by default, the number of sessions for the
application instances should be fairly close to each other. For example, this is fairly
normal:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 4268 Sessions: 0 Processed: 5 Uptime: 4m 52s
PID: 4265 Sessions: 1 Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 Processed: 7 Uptime: 3m 14s</pre>
</div>
</div>
<div class="paragraph"><p>But if you see a "spike", i.e. an application instance has an unusually high number of
sessions compared to the others, then there might be a problem:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 17468 Sessions: 8 <-+ Processed: 2 Uptime: 4m 47s
PID: 4265 Sessions: 1 | Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 | Processed: 7 Uptime: 3m 14s
|
+---- "spike"</pre>
</div>
</div>
<div class="paragraph"><p>The most likely reason why a spike occurs is because your application is frozen, i.e. it has stopped responding. See <a href="#debugging_frozen">Debugging frozen applications</a> for tips.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="debugging_frozen"></span><h3 data-comment-topic="debugging-frozen-applications-1qsjqq7" data-anchor="debugging_frozen">10.3. Debugging frozen applications</h3>
<div class="paragraph"><p>If one of your application instances is frozen (stopped responding), then you
can figure out where it is frozen by killing it with <em>SIGABRT</em>. This will cause the
application to raise an exception, with a backtrace.</p></div>
<div class="paragraph"><p>The exception (with full backtrace information) is normally logged into the web server
error log. But if your application or if its web framework has its own exception logging
routines, then exceptions might be logged into the application’s log files instead.
This is the case with Ruby on Rails. So if you kill a Ruby on Rails application with
<em>SIGABRT</em>, please check the application’s <em>production.log</em> first (assuming that you’re
running it in a <em>production</em> environment). If you don’t see a backtrace there, check
the web server error log.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">It is safe to kill application instances, even in live environments. Phusion Passenger
will restart killed application instances, as if nothing bad happened.</td>
</tr></table>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_accessing_individual_application_processes"></span><h3 data-comment-topic="accessing-individual-application-processes-1p0j4jb" data-anchor="_accessing_individual_application_processes">10.4. Accessing individual application processes</h3>
<div class="paragraph"><p>When a request is sent to the web server, Phusion Passenger will automatically forward
the request to the most suitable application process, but sometimes it is desirable to
be able to directly access the individual application processes. Use cases include, but
are not limited to:</p></div>
<div class="ulist"><ul>
<li>
<p>
One wants to debug a memory leak or memory bloat problem that only seems to appear on
certain URIs. One can send a request to a specific process to see whether that request
causes the process’s memory usage to rise.
</p>
</li>
<li>
<p>
The application caches data in local memory, and one wants to tell a specific
application process to clear that local data.
</p>
</li>
<li>
<p>
Other debugging use cases.
</p>
</li>
</ul></div>
<div class="paragraph"><p>All individual application processes are accessible via HTTP, so you can use standard
HTTP tools like <em>curl</em>. The exact addresses can be obtained with the command
<span class="monospaced">passenger-status --verbose</span>. These sockets are all bound to 127.0.0.1, but the port
number is dynamically assigned. As a security measure, the sockets are also protected
with a process-specific random password, which you can see in the
<span class="monospaced">passenger-status --verbose</span> output. This password must be sent through the
“X-Passenger-Connect-Password” HTTP header.</p></div>
<div class="paragraph"><p>Example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>bash# passenger-status --verbose
----------- General information -----------
max = 6
count = 2
active = 0
inactive = 2
Waiting on global queue: 0
----------- Application groups -----------
/Users/hongli/Sites/rack.test:
App root: /Users/hongli/Sites/rack.test
* PID: 24235 Sessions: 0 Processed: 7 Uptime: 17s
URL : http://127.0.0.1:58122
Password: nFfVOX1F8LjZ90HJh28Sd_htJOsgRsNne2QXKf8NIXw
* PID: 24250 Sessions: 0 Processed: 4 Uptime: 1s
URL : http://127.0.0.1:57933
Password: _RGXlQ9EGDGJKLevQ_qflUtF1KmxEo2UiRzMwIE1sBY</pre>
</div>
</div>
<div class="paragraph"><p>Here we see that the web application <em>rack.test</em> has two processes.
Process 24235 is accessible via <a href="http://127.0.0.1:58122">http://127.0.0.1:58122</a>, and
process 24250 is accessible via <a href="http://127.0.0.1:57933">http://127.0.0.1:57933</a>.</p></div>
<div class="paragraph"><p>To access 24235 we must send its password, <em>nFfVOX1F8LjZ90HJh28Sd_htJOsgRsNne2QXKf8NIXw</em>,
through the <em>X-Passenger-Connect-Password</em> HTTP header, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>bash# curl -H "X-Passenger-Connect-Password: nFfVOX1F8LjZ90HJh28Sd_htJOsgRsNne2QXKf8NIXw" http://127.0.0.1:58122/</pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_attaching_an_irb_console_to_an_application_process"></span><h3 data-comment-topic="attaching-an-irb-console-to-an-application-process-1cma32j" data-anchor="_attaching_an_irb_console_to_an_application_process">10.5. Attaching an IRB console to an application process</h3>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 3.0.0. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>You can attach an IRB console to any application process and inspect its state by executing arbitrary Ruby code. Do this by invoking <span class="monospaced">passenger-irb <PID></span> where <em><PID></em> is the PID of the application process you wish to inspect. Note that the IRB console is currently only available for Ruby apps, not for apps in any other languages.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_tips"></span><h2 data-comment-topic="tips-19cwwf7" data-anchor="_tips">11. Tips</h2>
<div class="sectionbody">
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="user_switching"></span><h3 data-comment-topic="user-switching-security--8njx1x" data-anchor="user_switching">11.1. User Switching (security feature)</h3>
<div class="paragraph"><p>Phusion Passenger supports automatic <em>user switching</em>: by default, it attempts to run applications as the "right" user, instead of running all applications as the same user.</p></div>
<div class="paragraph"><p>To better understand the problem, let us consider the situation with PHP.
There is a problem that plagues most PHP web hosts, namely the fact that all PHP
applications are run in the same user context as the web server. So for
example, Joe’s PHP application will be able to read Jane’s PHP application’s
passwords. This is obviously undesirable on many servers.</p></div>
<div class="paragraph"><p>Phusion Passenger’s <em>user switching</em> feature solves this problem. Applications are
run as the owner of their "startup file". For Ruby apps, the startup file is
<span class="monospaced">config.ru</span> (Rack and Rails >= 3) or <span class="monospaced">config/environment.rb</span> (Rails 1 and 2). For
Python apps, the startup file is <span class="monospaced">passenger_wsgi.py</span>. So suppose that <span class="monospaced">config.ru</span>
is owned by user <em>joe</em>, then Phusion Passenger will spawn the corresponding
application as <em>joe</em> as well. The exact rules are a little bit more complicated,
and they’re explained further down in this section.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_requirements"></span><h4 data-comment-topic="requirements-yxvtxo" data-anchor="_requirements">11.1.1. Requirements</h4>
<div class="paragraph"><p>User switching is only enabled when all of the following conditions are met:</p></div>
<div class="ulist"><ul>
<li>
<p>
When not using <a href="#flying_passenger">Flying Passenger</a> (this is probably the case):
</p>
<div class="ulist"><ul>
<li>
<p>
The
<a href="#PassengerUserSwitching">PassengerUserSwitching</a>
option must be enabled.
</p>
</li>
<li>
<p>
The web server’s control process must have root privileges. This is the case on most installations.
</p>
</li>
</ul></div>
</li>
<li>
<p>
When using <a href="#flying_passenger">Flying Passenger</a>:
</p>
<div class="ulist"><ul>
<li>
<p>
The Flying Passenger daemon must be run with root privileges.
</p>
</li>
</ul></div>
</li>
</ul></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_effects"></span><h4 data-comment-topic="effects-1lko7vo" data-anchor="_effects">11.1.2. Effects</h4>
<div class="paragraph"><p>When not using Flying Passenger, the following table illustrates the effect for different combinations of the requirements.</p></div>
<table class="tableblock frame-all grid-all" style="
width:100%;
">
<col style="width:33%;">
<col style="width:33%;">
<col style="width:33%;">
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>PassengerUserSwitching on</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>PassengerUserSwitching off</strong></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Web server has root privileges</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching enabled.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching disabled. Apps are run as
<a href="#PassengerDefaultUser">PassengerDefaultUser</a> and
<a href="#PassengerDefaultGroup">PassengerDefaultGroup</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Web server has no root privileges</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching disabled. Apps are run as the web server’s user.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching disabled. Apps are run as the web server’s user.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>When using Flying Passenger, the effect is as follows:</p></div>
<table class="tableblock frame-all grid-all" style="
width:100%;
">
<col style="width:50%;">
<col style="width:50%;">
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Daemon run with root privileges</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching enabled.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Daemon run without root privileges</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">User switching disabled. Apps are run as the daemon’s user.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>When user switching is enabled, the following rules are followed to determine what user an application should be run as. The first matching rule is the rule that will be followed.</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
If
<a href="#PassengerUser">PassengerUser</a> or
<a href="#PassengerGroup">PassengerGroup</a>
are set, then the application will be run as the specified user/group. Thus, these options are a good way to override user switching settings.
</p>
</li>
<li>
<p>
If the startup file is owned by root or an unknown user, then the application will run as the user specified by
<a href="#PassengerDefaultUser">PassengerDefaultUser</a> and
<a href="#PassengerDefaultGroup">PassengerDefaultGroup</a>.
</p>
</li>
<li>
<p>
Otherwise, the application is run as the owner of the startup file.
</p>
</li>
</ol></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_caveats_amp_troubleshooting"></span><h4 data-comment-topic="caveats-troubleshooting-161hgge" data-anchor="_caveats_amp_troubleshooting">11.1.3. Caveats & troubleshooting</h4>
<div class="paragraph"><p>If your application regularly encounters permission errors or fails to find certain files, then this is an indication that your application is started as a user that you did not intent it to be run as. Other symptoms include:</p></div>
<div class="ulist"><ul>
<li>
<p>
The application fails to start because Bundler complains that it cannot find gems. This probably indicates that Bundler does not have read access to the directory that contains Bundler-installed gems.
</p>
</li>
<li>
<p>
The application fails to start and its error message mentions the path <em>/nonexistent</em>. This probably indicates that your application is started as the <em>nobody</em> user. This is because on many systems, the <em>nobody</em> user’s home directory is <em>/nonexistent</em>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>To check whether it is indeed the case that your application is started as a different user than you intended to, see <a href="#finding_out_app_user">Finding out what user an application is running as</a>.</p></div>
<div class="paragraph"><p>The most likely reason why your application is started as <em>nobody</em> is probably because your startup file is owned by <em>root</em>, by <em>nobody</em> or by an unknown user. To fix this, change the owner of the startup file to the owner that you want to run the application as.</p></div>
<div class="paragraph"><p>Whatever user your application runs as, it must have read access to the <a href="#application_root">application root</a>, and read/write access to the application’s <em>logs</em> directory.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="finding_out_app_user"></span><h4 data-comment-topic="finding-out-what-user-an-application-is-running-as-7uwrol" data-anchor="finding_out_app_user">11.1.4. Finding out what user an application is running as</h4>
<div class="paragraph"><p>To find our what user an application is started as, first access its URL in your browser so that Phusion Passenger starts the application. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>http://www.example.local/</pre>
</div>
</div>
<div class="paragraph"><p>The application will now either successfully start or fail to start. If it fails to start then you will see an error page that tells you what user the application was being started as. If you do not see the error page in the browser then set
<a href="#PassengerFriendlyErrorPages">PassengerFriendlyErrorPages</a>
on.</p></div>
<div class="paragraph"><p>If the application successfully started, then run <span class="monospaced">passenger-status</span> to find the process’s PID:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>.---------- General information -----------
Max pool size : 6
Processes : 1
Requests in top-level queue : 0
.---------- Application groups -----------
/webapps/example.local#default:
App root: /webapps/example.local
Requests in queue: 0
* PID: 16915 Sessions: 0 Processed: 1 Uptime: 2s
CPU: 0% Memory : 9M Last used: 2s ago</pre>
</div>
</div>
<div class="paragraph"><p>In the above example we see that the PID is 16915. Next, use <em>ps</em> to find out the user that it is running as:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># ps -o pid,user,comm -p 16915
PID USER COMM
16915 phusion Passenger RackApp: /webapps/example.local</pre>
</div>
</div>
<div class="paragraph"><p>As you can see, the application in this example is being run as user <em>phusion</em>.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="reducing_memory_usage"></span><h3 data-comment-topic="reducing-memory-consumption-of-ruby-on-rails-applications-by-33--1ubxnq0" data-anchor="reducing_memory_usage">11.2. Copy-on-write memory support (reducing memory consumption of Ruby applications)</h3>
<div class="paragraph"><p>Phusion Passenger automatically leverages operating system virtual memory copy-on-write features in order to reduce the memory usage of Ruby applications. Experience has shown that this reduces memory usage by 33% on average. For this mechanism to work, a Ruby interpreter with a copy-on-write friendly garbage collector is required. The following Ruby interpreters have copy-on-write friendly garbage collectors:</p></div>
<div class="ulist"><ul>
<li>
<p>
MRI Ruby >= 2.0. Versions prior to 2.0 did not have a copy-on-write friendly garbage collector.
</p>
</li>
<li>
<p>
<a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>, which was Phusion’s branch of MRI Ruby 1.8 with a copy-on-write friendly garbage collector and other enhancement. It has reached End-Of-Life as of 2012, but remains available for legacy systems.
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="capistrano"></span><h3 data-comment-topic="capistrano-recipe-syzgo7" data-anchor="capistrano">11.3. Capistrano recipe</h3>
<div class="paragraph"><p>Phusion Passenger can be combined with <a href="http://capify.org/">Capistrano</a>.
The following Capistrano recipe demonstrates Phusion Passenger support.
It assumes that you’re using Git as version control system.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>set :application, "myapp"
set :domain, "example.com"
set :repository, "ssh://#{domain}/path-to-your-git-repo/#{application}.git"
set :use_sudo, false
set :deploy_to, "/path-to-your-web-app-directory/#{application}"
set :scm, "git"
role :app, domain
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end</pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="bundler_support"></span><h3 data-comment-topic="bundler-support-cf72ih" data-anchor="bundler_support">11.4. Bundler support</h3>
<div class="paragraph"><p>Phusion Passenger has automatic support for <a href="http://gembundler.com/git.html">Bundler</a>.
The support consists of loading your application under the environment defined by your
Gemfile. In other words, Phusion Passenger loads your application as if <em>bundle exec</em> was used.</p></div>
<div class="paragraph"><p>The Bundler support works as follows:</p></div>
<div class="ulist"><ul>
<li>
<p>
If you have a <em>.bundle/environment.rb</em> in your application root, then Phusion
Passenger will require that file before loading your application.
</p>
</li>
<li>
<p>
Otherwise, if you have a <em>Gemfile</em>, then Phusion Passenger will automatically call
<span class="monospaced">Bundler.setup()</span> before loading your application.
</p>
</li>
</ul></div>
<div class="paragraph"><p>It’s possible that your application also calls <span class="monospaced">Bundler.setup</span> during loading, e.g. in
<em>config.ru</em> or in <em>config/boot.rb</em>. This is the case with Rails 3, and is also the case if you
modified your <em>config/boot.rb</em> according to the
<a href="http://gembundler.com/rails23.html">Bundler Rails 2.3 instructions</a>.
This leads to <span class="monospaced">Bundler.setup</span> being called twice, once before the application startup file
is required and once during application startup. However this is harmless and doesn’t
have any negative effects.</p></div>
<div class="paragraph"><p>Phusion Passenger assumes that you’re using Bundler >= 0.9.5. If you don’t want Phusion
Passenger to run its Bundler support code, e.g. because you need to use an older version
of Bundler with an incompatible API or because you use a system other than Bundler, then
you can override Phusion Passenger’s Bundler support code by creating an empty file
<em>config/setup_load_paths.rb</em>. If this file exists then it will be required before loading
the application startup file. In this file you can do whatever you need to setup Bundler
or a similar system.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="add_passenger_to_gemfile"></span><h4 data-comment-topic="does-phusion-passenger-itself-need-to-be-added-to-the-gemfile--17whimp" data-anchor="add_passenger_to_gemfile">11.4.1. Does Phusion Passenger itself need to be added to the Gemfile?</h4>
<div class="paragraph"><p>It is never necessary to add Phusion Passenger to the application’s Gemfile. In case of Phusion Passenger Standalone, it is not necessary to execute the <span class="monospaced">passenger</span> command through <span class="monospaced">bundle exec</span>. The reason for this is because Phusion Passenger automatically loads the Gemfile environment. Most other Ruby application servers do not automatically load the Gemfile environment, which is why they must be added to the Gemfile and be executed with <span class="monospaced">bundle exec</span>.</p></div>
<div class="paragraph"><p>Even when your application uses any of the Phusion Passenger APIs, you still do not need to add Phusion Passenger to the Gemfile. The only thing you need to do is to put Phusion Passenger API calls inside <span class="monospaced">if</span> blocks that check whether Phusion Passenger is active, by checking whether the <span class="monospaced">PhusionPassenger</span> namespace is defined:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><strong>if</strong> defined?(PhusionPassenger)
...
<strong>end</strong></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_installing_multiple_ruby_on_rails_versions"></span><h3 data-comment-topic="installing-multiple-ruby-on-rails-versions-mi5j14" data-anchor="_installing_multiple_ruby_on_rails_versions">11.5. Installing multiple Ruby on Rails versions</h3>
<div class="paragraph"><p>Each Ruby on Rails applications that are going to be deployed may require a
specific Ruby on Rails version. You can install a specific version with
this command:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>gem install rails -v X.X.X</pre>
</div>
</div>
<div class="paragraph"><p>where <em>X.X.X</em> is the version number of Ruby on Rails.</p></div>
<div class="paragraph"><p>All of these versions will exist in parallel, and will not conflict with each
other. Phusion Passenger will automatically make use of the correct version.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_making_the_application_restart_after_each_request"></span><h3 data-comment-topic="making-the-application-restart-after-each-request-183bezx" data-anchor="_making_the_application_restart_after_each_request">11.6. Making the application restart after each request</h3>
<div class="paragraph"><p>In some situations it might be desirable to restart the web application after
each request, for example when developing a non-Rails application that doesn’t
support code reloading, or when developing a web framework.</p></div>
<div class="paragraph"><p>To achieve this, simply create the file <em>tmp/always_restart.txt</em> in your
application’s root folder. Unlike <em>restart.txt</em>, Phusion Passenger does not
check for this file’s timestamp: Phusion Passenger will always restart the
application, as long as <em>always_restart.txt</em> exists.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">If you’re just developing a Rails application then you probably don’t need
this feature. If you set
<em>RailsEnv development</em>
in your web server configuration,
then Rails will automatically reload your application code after each request.
<em>always_restart.txt</em> is mostly useful when you’re using a web framework that
doesn’t support code reloading by itself, of when you’re working on a web framework
yourself.</td>
</tr></table>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="sub_uri_deployment_uri_fix"></span><h3 data-comment-topic="how-to-fix-broken-images-css-javascript-uris-in-sub-uri-deployments-a63b6r" data-anchor="sub_uri_deployment_uri_fix">11.7. How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</h3>
<div class="paragraph"><p>Some people experience broken images and other broken static assets when they
deploy their application to a sub-URI (i.e. <em>http://mysite.com/railsapp/</em>).
The reason for this usually is that you used a
static URI for your image in the views. This means your <em>img</em> source probably refers
to something like <em>/images/foo.jpg</em>. The leading slash means that it’s an absolute URI:
you’re telling the browser to always load <em>http://mysite.com/images/foo.jpg</em> no
matter what. The problem is that the image is actually at
<em>http://mysite.com/railsapp/images/foo.jpg</em>. There are two ways to fix this.</p></div>
<div class="paragraph"><p>The first way (not recommended) is to change your view templates to refer to
<em>images/foo.jpg</em>. This is a relative URI: note the lack of a leading slash). What
this does is making the path relative to the current URI. The problem is that if you
use restful URIs, then your images will probably break again when you add a level to
the URI.
For example, when you’re at <em>http://mysite.com/railsapp</em> the browser will look for
<em>http://mysite.com/railsapp/images/foo.jpg</em>. But when you’re at
<em>http://mysite.com/railsapp/controller</em>. the browser will look for
<em>http://mysite.com/railsapp/controller/images/foo.jpg</em>.
So relative URIs usually don’t work well with layout templates.</p></div>
<div class="paragraph"><p>The second and highly recommended way is to always use Rails helper methods to
output tags for static assets. These helper methods automatically take care
of prepending the base URI that you’ve deployed the application to. For images
there is <span class="monospaced">image_tag</span>, for JavaScript there is <span class="monospaced">javascript_include_tag</span> and for
CSS there is <span class="monospaced">stylesheet_link_tag</span>. In the above example you would simply remove
the <em><img></em> HTML tag and replace it with inline Ruby like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre><%= image_tag("foo.jpg") %></pre>
</div>
</div>
<div class="paragraph"><p>This will generate the proper image tag to <span class="monospaced">$RAILS_ROOT/public/images/foo.jpg</span>
so that your images will always work no matter what sub-URI you’ve deployed to.</p></div>
<div class="paragraph"><p>These helper methods are more valuable than you may think. For example they also
append a timestamp to the URI to better facilitate HTTP caching. For more information,
please refer to
<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">the Rails API docs</a>.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_out_of_band_work_and_out_of_band_garbage_collection"></span><h3 data-comment-topic="out-of-band-work-and-out-of-band-garbage-collection-kav2p8" data-anchor="_out_of_band_work_and_out_of_band_garbage_collection">11.8. Out-of-Band Work and Out-of-Band Garbage Collection</h3>
<div class="paragraph"><p><strong>Available since Phusion Passenger 4.0.0.</strong></p></div>
<div class="paragraph"><p><strong>At this time, this feature is only available on Ruby.</strong></p></div>
<div class="paragraph"><p>The Out-of-Band Work feature allows you to run arbitrary long-running tasks outside normal request cycles. This works by letting current requests to the process finish, then telling the process to perform the out-of-band work, then resuming passing requests to the process after said work is finished.</p></div>
<div class="paragraph"><p>A specific (and perhaps primary) use case of of Out-of-Band Work is <strong>Out-of-Band Garbage Collection</strong>. The garbage collector is run outside normal request cycles so that garbage collection runs inside normal request cycles can finish a lot faster. This can potentially save tens to hundreds of milliseconds of latency in requests.</p></div>
<div class="paragraph"><p>Because Out-of-Band Work is implemented at the Phusion Passenger inter-process request routing level, and not by, say, spawning a thread inside the application process, Out-of-Band Work has the following useful properties:</p></div>
<div class="ulist"><ul>
<li>
<p>
It works well even with tasks that can pause all threads. The MRI Ruby garbage collector is a stop-the-world mark-and-sweep garbage collector.
</p>
</li>
<li>
<p>
Phusion Passenger can spawn more processes as necessary, in order to prevent situations in which all application processes are busy performing out-of-band work. Phusion Passenger guarantees that there’s at least one process that’s ready to process requests.
</p>
</li>
<li>
<p>
Phusion Passenger guarantees that no more than 1 process is performing out-of-band work at the same time.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Applications can use Out-of-Band Work as follows:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Ensure that
<a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a>
and
<a href="#PassengerMinInstances">PassengerMinInstances</a>
are both larger than 1. Out-of-band work only works if there are at least 2 application processes.
</p>
</li>
<li>
<p>
Request out-of-band work by outputting the <span class="monospaced">X-Passenger-Request-OOB-Work</span> header during a request. It does not matter what the value is. At this time, it is not possible to request out-of-band work from outside requests.
</p>
</li>
<li>
<p>
You can actually perform out-of-band work when you receive a <span class="monospaced">:oob_work</span> Phusion Passenger event.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Note that even though you can request out-of-band work, there’s no guarantee that Phusion Passenger will send an <span class="monospaced">oob_work</span> event in a timely manner, if at all. It is also possible that Phusion Passenger sends an <span class="monospaced">oob_work</span> event without you ever having requested one. This latter could for example happen if the OOB work is administrator-initiated. Do not make any assumptions in your code.</p></div>
<div class="paragraph"><p>Here’s an example which implements out-of-band garbage collection using the Out-of-Band framework. This example code doesn’t do anything when the code is not being run in Phusion Passenger, thanks to the <span class="monospaced">if</span> block.</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Somewhere in a controller method:</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># Tell Phusion Passenger we want to perform OOB work.</span></span>
response<span style="color: #990000">.</span>headers<span style="color: #990000">[</span><span style="color: #FF0000">"X-Passenger-Request-OOB-Work"</span><span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">"true"</span>
<span style="font-style: italic"><span style="color: #9A1900"># Somewhere during application initialization:</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>oob_work<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># Phusion Passenger has told us that we're ready to perform OOB work.</span></span>
t0 <span style="color: #990000">=</span> Time<span style="color: #990000">.</span>now
GC<span style="color: #990000">.</span>start
Rails<span style="color: #990000">.</span>logger<span style="color: #990000">.</span>info <span style="color: #FF0000">"Out-Of-Bound GC finished in #{Time.now - t0} sec"</span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre>
</div>
</div>
<div class="paragraph"><p>For your convenience, Phusion Passenger provides a Rack middleware for out-of-band garbage collection. Add the following to your <span class="monospaced">config.ru</span>. Likewise, this example code doesn’t do anything when the code is not being run in Phusion Passenger, thanks to the <span class="monospaced">if</span> block.</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>require_passenger_lib <span style="color: #FF0000">'rack/out_of_band_gc'</span>
<span style="font-style: italic"><span style="color: #9A1900"># Trigger out-of-band GC every 5 requests.</span></span>
use PhusionPassenger<span style="color: #990000">::</span>Rack<span style="color: #990000">::</span>OutOfBandGc<span style="color: #990000">,</span> <span style="color: #993399">5</span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre>
</div>
</div>
<div class="paragraph"><p>It should be noted that, although the application uses the Phusion Passenger API, it is <a href="#add_passenger_to_gemfile"><strong>not</strong> necessary to add Phusion Passenger to the Gemfile</a>.</p></div>
<div class="paragraph"><p>References:</p></div>
<div class="ulist"><ul>
<li>
<p>
<a href="http://blog.phusion.nl/2013/01/22/phusion-passenger-4-technology-preview-out-of-band-work/">The Phusion Blog article which first introduced this feature.</a>
</p>
</li>
</ul></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_hooks"></span><h3 data-comment-topic="hooks-bcltgp" data-anchor="_hooks">11.9. Hooks</h3>
<div class="paragraph"><p><strong>Introduced in version 4.0.28.</strong></p></div>
<div class="paragraph"><p>Phusion Passenger provides a powerful but simple hooking system, which allows you to extend many aspects of Phusion Passenger’s behavior. The hooking system works by executing commands during certain events. Event parameters are passed to the command in the form of environment variables.</p></div>
<div class="paragraph"><p>You can define hooks by setting the configuration option <span class="monospaced">PassengerCtl hook_<HOOK NAME> <COMMAND TO EXECUTE></span>.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_example"></span><h4 data-comment-topic="example-icjf0z" data-anchor="_example">11.9.1. Example</h4>
<div class="paragraph"><p>The hook system is best demonstrated with a simple example. In the following example we will hook into the <span class="monospaced">attached_process</span> event. This event is called whenever Phusion Passenger has successfully spawned an application processes and added it to the process pool. We print the process’s PID and application root.</p></div>
<div class="paragraph"><p>First, let’s create a script <span class="monospaced">/home/phusion/attached.sh</span> which is to be called during the hook.</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">#!/bin/sh</span></span>
echo <span style="color: #FF0000">"Attached process $PASSENGER_PROCESS_PID for app $PASSENGER_APP_ROOT."</span></tt></pre>
</div>
</div>
<div class="paragraph"><p>Then we make it executable:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>chmod +x /home/phusion/attached.sh</pre>
</div>
</div>
<div class="paragraph"><p>And we define the hook in the configuration file:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>PassengerCtl hook_attached_process /home/phusion/attached.sh</pre>
</div>
</div>
<div class="paragraph"><p>Now restart the web server and access a web app hosted by Phusion Passenger. You should see our message in the web server error log:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>[ 2013-12-10 16:12:21.6456 28934/0x1064cb000 Hooks.h:129 ]: Running attached_process hook script: /home/phusion/attached.sh
Attached process 28303 for app /webapps/foobar.
[ 2013-12-10 16:12:21.6580 28934/0x1064cb000 Hooks.h:161 ]: Hook script /home/phusion/attached.sh (PID 28948) exited with status 0</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_environment"></span><h4 data-comment-topic="environment-1amls4v" data-anchor="_environment">11.9.2. Environment</h4>
<div class="paragraph"><p>A lot of information is passed to hook scripts in the form of environment variables. They are all uppercase and begin with <span class="monospaced">PASSENGER_</span>. Some environment variables are passed to all hook scripts, others are passed depending on the hook.</p></div>
<div class="paragraph"><p>Here are some of the environment variables which are passed to all hooks, unless documented otherwise:</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">PASSENGER_VERSION</span>
</p>
</li>
<li>
<p>
<span class="monospaced">PASSENGER_PASSENGER_ROOT</span>
</p>
</li>
<li>
<p>
<span class="monospaced">PASSENGER_SERVER_INSTANCE_DIR</span>
</p>
</li>
<li>
<p>
<span class="monospaced">PASSENGER_GENERATION_PATH</span>
</p>
</li>
</ul></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_blocking_and_concurrency"></span><h4 data-comment-topic="blocking-and-concurrency-cxpbyu" data-anchor="_blocking_and_concurrency">11.9.3. Blocking and concurrency</h4>
<div class="paragraph"><p>All hooks block. That is, Phusion Passenger waits until your hook command is finished. You should therefore be careful when writing hook scripts: if your script never finishes, so Phusion Passenger does not do that either.</p></div>
<div class="paragraph"><p>If you have a bug in your script and it blocks, then you will be able to see that using the command <span class="monospaced">passenger-status --show=backtraces</span> which prints the backtraces of all threads in the Phusion Passenger HelperAgent. Look for the <span class="monospaced">runSingleHookScript</span> function in the backtrace. The following example shows at line 2 that Phusion Passenger is waiting for the hook script <span class="monospaced">/home/phusion/badscript.sh</span>.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Thread 'Group process spawner: /home/phusion/webapp.test#default' (0x1062d4000):
in 'bool Passenger::runSingleHookScript(Passenger::HookScriptOptions &, const string &, const vector<pair<string, string> > &)' (Hooks.h:116) -- /home/phusion/badscript.sh
in 'bool Passenger::runHookScripts(Passenger::HookScriptOptions &)' (Hooks.h:159)
in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr &, const Passenger::ApplicationPool2::Options &, unsigned int)' (Implementation.cpp:878)</pre>
</div>
</div>
<div class="paragraph"><p>Hooks may be called concurrently. For example, while the <span class="monospaced">attached_process</span> hook is being called, a <span class="monospaced">detached_process</span> hook may be called, perhaps even for the same application. It is your responsibility to ensure that your hook scripts are concurrency-safe, e.g. by employing locks and other concurrency control techniques.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_error_handling"></span><h4 data-comment-topic="error-handling-1a1uvod" data-anchor="_error_handling">11.9.4. Error handling</h4>
<div class="paragraph"><p>If a hook script fails — that is, if it exits with anything other than exit code 0 — then the error handling depends on the hook. Some hooks will abort, other hooks will ignore the error. In all cases, the result of the hook script is printed to the log.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_compatibility"></span><h4 data-comment-topic="compatibility-18tl6g3" data-anchor="_compatibility">11.9.5. Compatibility</h4>
<div class="paragraph"><p>Because hooks are inherently tied to the implementation of Phusion Passenger, there is no guarantee that hooks that currently work will continue to be available in the future versions of Phusion Passenger. The availability of hooks is very much tied to the specific version of Phusion Passenger.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_available_hooks"></span><h4 data-comment-topic="available-hooks-159anc3" data-anchor="_available_hooks">11.9.6. Available hooks</h4>
<div class="dlist"><dl>
<dt class="hdlist1">
<span class="monospaced">before_watchdog_initialization</span>
</dt>
<dd>
<p>
Called at the very beginning of Phusion Passenger’s life cycle, during the start of the Watchdog process. The first hook is called before initialization is performed (before the HelperAgent is started). Errors in the hook script cause Phusion Passenger to abort.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">after_watchdog_initialization</span>
</dt>
<dd>
<p>
Like <span class="monospaced">before_watchdog_initialization</span>, but called after initialization of all Phusion Passenger agent processes. Errors in the hook script cause Phusion Passenger to abort.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">attached_process</span>
</dt>
<dd>
<p>
Called when Phusion Passenger has successfully spawned an application processes and added it to the process pool. Extra environment variables: <span class="monospaced">PASSENGER_PROCESS_PID</span>, <span class="monospaced">PASSENGER_APP_ROOT</span>. Errors in the hook script are ignored.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">detached_process</span>
</dt>
<dd>
<p>
Called when Phusion Passenger has removed an application process from the process pool. This could happen when:
</p>
<div class="ulist"><ul>
<li>
<p>
The process has crashed, and Phusion Passenger noticed it.
</p>
</li>
<li>
<p>
Phusion Passenger has shut down a process because it’s been idle for too long.
</p>
</li>
<li>
<p>
The administrator configured different resource limits, and Phusion Passenger is starting or shutting down processes in response.
</p>
</li>
<li>
<p>
Phusion Passenger itself is shutting down.
</p>
<div class="paragraph"><p>Extra environment variables: <span class="monospaced">PASSENGER_PROCESS_PID</span>, <span class="monospaced">PASSENGER_APP_ROOT</span>. Errors in the hook script are ignored.</p></div>
</li>
</ul></div>
</dd>
<dt class="hdlist1">
<span class="monospaced">after_initialize_supergroup</span>
</dt>
<dd>
<p>
Called right after Phusion Passenger has allocated data structures for an application, and is about to spawn a process for the first time for this application. Errors in the hook script are ignored. Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.
</p>
</dd>
<dt class="hdlist1">
<span class="monospaced">before_destroy_supergroup</span>
</dt>
<dd>
<p>
Called right before Phusion Passenger decallocates data structures for an application. Errors in the hook script are ignored.
</p>
<div class="paragraph"><p>Note that the <span class="monospaced">after_initialize_supergroup</span> hook may be called while this hook is still being executed, so make sure that operations don’t conflict with each other.</p></div>
<div class="paragraph"><p>Extra environment variables: <span class="monospaced">PASSENGER_APP_ROOT</span>.</p></div>
</dd>
</dl></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="flying_passenger"></span><h3 data-comment-topic="flying-passenger-q916f7" data-anchor="flying_passenger">11.10. Flying Passenger</h3>
<div class="paragraph"><p><strong>This feature is only available in <a href="https://www.phusionpassenger.com/enterprise">Phusion Passenger Enterprise</a>. It was introduced in version 4.0.6. <a href="https://www.phusionpassenger.com/download">Buy Phusion Passenger Enterprise here.</a></strong></p></div>
<div class="paragraph"><p>Flying Passenger allows one to decouple Phusion Passenger’s life time from the web server’s life time, so that the web server can be independently restarted from Phusion Passenger, and from any of the application processes served by Phusion Passenger.</p></div>
<div class="paragraph"><p>Normally, Phusion Passenger starts together with the web server, and shuts down together with the web server. The advantages of this default behavior is that it makes Phusion Passenger easy to administer: one only has to deal with the web server process and can expect all relevant processes to be cleaned up after a web server shut down. However this also brings about a disadvantage: every time one restarts the web server (e.g. to make a minor configuration change), Phusion Passenger and all its application processes also get restarted.</p></div>
<div class="paragraph"><p>This problem is solved by <em>Flying Passenger</em>, which is an advanced mode of operation in Phusion Passenger that allows the web server to be indepedently restarted from Phusion Passenger. When this mode is enabled:</p></div>
<div class="ulist"><ul>
<li>
<p>
One must start Phusion Passenger separately from the web server, namely by starting the Flying Passenger daemon. This daemon must - to an extent - be separately configured and managed from the web server.
</p>
</li>
<li>
<p>
The web server must be configured to forward requests to the Flying Passenger daemon.
</p>
</li>
<li>
<p>
You should beware of the <a href="#flying_passenger_caveats">caveats and limitations</a>.
</p>
</li>
</ul></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_requirements_2"></span><h4 data-comment-topic="requirements-1ntkin3" data-anchor="_requirements_2">11.10.1. Requirements</h4>
<div class="paragraph"><p>At this time, this feature is <strong>only available in the Enterprise version of Phusion Passenger for Nginx</strong>. You must have Phusion Passenger for Nginx properly installed.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_basic_usage"></span><h4 data-comment-topic="basic-usage-joifsk" data-anchor="_basic_usage">11.10.2. Basic usage</h4>
<div class="paragraph"><p>Start the Flying Passenger daemon by invoking the <span class="monospaced">flying-passenger</span> command. The only required option is <span class="monospaced">--socket-file</span>. Depending on whether you wish to enable <a href="#user_switching">User Switching</a>, you have to start <span class="monospaced">flying-passenger</span> with root privileges or not.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo flying-passenger --socket-file=/var/run/flying-passenger.sock
I, [2013-06-14T09:10:13.095339 #77179] INFO -- : Welcome to Flying Passenger 4.1.0
I, [2013-06-14T09:10:13.095339 #77179] INFO -- : Starting PassengerWatchdog...
I, [2013-06-14T09:10:13.097036 #77179] INFO -- : PassengerWatchdog started on PID 77181
...
I, [2013-06-14T09:10:13.129017 #77179] INFO -- : PassengerWatchdog initialized properly
I, [2013-06-14T09:10:13.129127 #77179] INFO -- : Flying Passenger up and listening on /var/run/flying-passenger.sock!</pre>
</div>
</div>
<div class="paragraph"><p>Now configure Phusion Passenger for Nginx to make use of the Flying Passenger daemon, by setting the <span class="monospaced">passenger_fly_with</span> option to the socket filename:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>http {
...
passenger_fly_with /var/run/flying-passenger.sock;
...
}</pre>
</div>
</div>
<div class="paragraph"><p>After (re)starting Nginx, Nginx + Flying Passenger is fully operational:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo /path-to/nginx</pre>
</div>
</div>
<div class="paragraph"><p>You can test it by adding a virtual host for a web app:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>http {
...
server {
listen 80;
server_name www.foo.local;
root /webapps/foo/public;
passenger_enabled on;
}
}</pre>
</div>
</div>
<div class="paragraph"><p>Verify that it works by making an HTTP request to it:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ curl http://www.foo.local/</pre>
</div>
</div>
<div class="paragraph"><p>Now let’s verify that restarting the web server does not restart the just-spawned application process. Run <span class="monospaced">passenger-status</span> to obtain the PID of the application process:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo passenger-status
Version: 4.1.0
Date : 2013-06-14 09:21:51 -0400
.---------- General information -----------
Max pool size : 6
Processes : 1
Requests in top-level queue : 0
.---------- Application groups -----------
/webapps/foo#default:
App root: /webapps/foo
Requests in queue: 0
* PID: 77283 Sessions: 0 Processed: 1 Uptime: 2s
CPU: 1% Memory : 8M Last used: 2s ago</pre>
</div>
</div>
<div class="paragraph"><p>As you can see, the PID of the application process is <strong>77283</strong>. Now let’s see what happens if we restart Nginx:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo /path-to/nginx -s stop
$ sudo /path-to/nginx
$ sudo passenger-status</pre>
</div>
</div>
<div class="paragraph"><p>The application process should remain there, unchanged:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo passenger-status
Version: 4.1.0
Date : 2013-06-14 09:21:51 -0400
.---------- General information -----------
Max pool size : 6
Processes : 1
Requests in top-level queue : 0
.---------- Application groups -----------
/webapps/foo#default:
App root: /webapps/foo
Requests in queue: 0
* PID: 77283 Sessions: 0 Processed: 1 Uptime: 18s
CPU: 1% Memory : 8M Last used: 18s ago</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="configuring_flying_passenger"></span><h4 data-comment-topic="configuring-flying-passenger-1v35vgg" data-anchor="configuring_flying_passenger">11.10.3. Configuring Flying Passenger</h4>
<div class="paragraph"><p>Flying Passenger gets <strong>some</strong> configuration from the web server, but not all. In particular, most web server directives that are only valid in the <span class="monospaced">http</span> context, e.g. <a href="#PassengerLogLevel">passenger_log_level</a>, have no effect when using Flying Passenger. Instead, you are supposed to pass these configuration directives through command line options to the Flying Passenger daemon. Configuration directives that have no effect on Flying Passenger are documented as such. You can assume that configuration directives that are not documented as such, work fine on Flying Passenger.</p></div>
<div class="paragraph"><p>For example, to achieve the same effect as setting passenger_log_level to 2, run the Flying Passenger daemon as follows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo flying-passenger --socket-file=/var/run/flying-passenger.sock --log-level=2</pre>
</div>
</div>
<div class="paragraph"><p>Currently, not all configuration directives have a Flying Passenger equivalent. Run the following command to see an overview of available options:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ flying-passenger --help</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_managing_the_flying_passenger_daemon"></span><h4 data-comment-topic="managing-the-flying-passenger-daemon-1bng2bu" data-anchor="_managing_the_flying_passenger_daemon">11.10.4. Managing the Flying Passenger daemon</h4>
<div class="paragraph"><p>The Flying Passenger daemon runs in the foreground by default. This is undesirable on server environments. You can make it go into the background by passing <span class="monospaced">--daemonize</span>, <span class="monospaced">--log-file</span> and <span class="monospaced">--pid-file</span>:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo flying-passenger --socket-file=/var/run/flying-passenger.sock \
--daemonize --log-file=/var/log/flying-passenger.log \
--pid-file=/var/run/flying-passenger.pid</pre>
</div>
</div>
<div class="paragraph"><p>You can shut down a Flying Passenger daemon by sending SIGINT or SIGTERM to it:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ kill `cat /var/run/flying-passenger.pid`</pre>
</div>
</div>
<div class="paragraph"><p>We recommend using <a href="http://cr.yp.to/daemontools.html">daemontools</a> or <a href="http://smarden.org/runit/">runit</a> for managing the Flying Passenger daemon. These tools will allow automatically starting the Flying Passenger daemon at boot, and will automatically restart the daemon if it crashes. You can create and enable a daemontools/runit service as folows:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ sudo mkdir /etc/service/flying-passenger
$ sudo nano /etc/service/flying-passenger/run
#!/bin/sh
exec /path-to/flying-passenger \
--socket-file=/var/run/flying-passenger.sock \
--log-file=/var/log/flying-passenger.log \
--pid-file=/var/run/flying-passenger.pid</pre>
</div>
</div>
<div class="paragraph"><p>Immediately after creating the <span class="monospaced">run</span> file, daemontools/runit automatically runs it to start the daemon. Note that the location (<span class="monospaced">/etc/service</span>) depends on the OS or Linux distros. Sometimes it’s <span class="monospaced">/service</span>. Also note that we start the Flying Passenger daemon without <span class="monospaced">--daemonize</span>.</p></div>
<div class="paragraph"><p>To shut down a daemontools/runit-managed daemon, you need to use <span class="monospaced">svc -d /etc/service/flying-passenger</span> (daemontools) or <span class="monospaced">sv stop /etc/service/flying-passenger</span> (runit) instead of sending a signal to the process.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="using_flying_passenger_with_mri_18_or_jruby"></span><h4 data-comment-topic="using-flying-passenger-with-mri-1-8-or-jruby-f5tbvs" data-anchor="using_flying_passenger_with_mri_18_or_jruby">11.10.5. Using Flying Passenger with MRI 1.8 or JRuby</h4>
<div class="paragraph"><p>Using Flying Passenger in combination with MRI Ruby 1.8 or with JRuby requires special attention. This is because the Flying Passenger daemon is written in Ruby, and requires proper <span class="monospaced">Process.spawn</span> support, which neither MRI 1.8 nor JRuby support.</p></div>
<div class="paragraph"><p>It is however possible to use Flying Passenger with MRI Ruby 1.8 and JRuby. You can’t run the Flying Passenger daemon in MRI 1.8 or JRuby, but you can still run the web applications - hosted under Flying Passenger - in MRI 1.8 or JRuby.</p></div>
<div class="paragraph"><p>First, edit your Nginx configuration file and specify a Ruby interpreter for your web applications. For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># Connect to the Flying Passenger daemon on the following socket
passenger_fly_with /var/run/flying-passenger.sock;
...
server {
listen 80;
server_name www.foo.com;
root /webapps/foo/public;
passenger_enabled on;
# Use JRuby for this web application
passenger_ruby /opt/jruby/bin/jruby;
}</pre>
</div>
</div>
<div class="paragraph"><p>Then you need to install a Ruby 1.9-compatible Ruby interpeter with POSIX spawn support, alongside JRuby/MRI 1.8. Ruby interpreters which can be used for running the Flying Passenger daemon include:</p></div>
<div class="ulist"><ul>
<li>
<p>
MRI Ruby >= 1.9.
</p>
</li>
<li>
<p>
Rubinius.
</p>
</li>
</ul></div>
<div class="paragraph"><p>The following example demonstrates how you can install MRI Ruby 1.9 in parallel with your MRI Ruby 1.8 or JRuby installation.</p></div>
<div class="paragraph"><p>Example for Debian/Ubuntu users:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Install Ruby 1.9</span></span>
sudo apt-get install ruby1<span style="color: #990000">.</span><span style="color: #993399">9.3</span>
<span style="font-style: italic"><span style="color: #9A1900"># Run the Flying Passenger daemon in Ruby 1.9</span></span>
ruby1<span style="color: #990000">.</span><span style="color: #993399">9</span> -S flying-passenger --socket-file<span style="color: #990000">=</span>/var/run/flying-passenger<span style="color: #990000">.</span>sock</tt></pre>
</div>
</div>
<div class="paragraph"><p>Example for RVM users:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># Install Ruby 1.9</span></span>
rvm install <span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>
<span style="font-style: italic"><span style="color: #9A1900"># Run the Flying Passenger daemon in Ruby 1.9</span></span>
$ rvm-exec <span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span> ruby -S flying-passenger --socket-file<span style="color: #990000">=</span>/var/run/flying-passenger<span style="color: #990000">.</span>sock</tt></pre>
</div>
</div>
<div class="paragraph"><p>The Flying Passenger daemon will now be run on Ruby 1.9, while the web application <em>www.foo.com</em> will be run on JRuby.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="flying_passenger_caveats"></span><h4 data-comment-topic="caveats-and-limitations-lz3rbb" data-anchor="flying_passenger_caveats">11.10.6. Caveats and limitations</h4>
<div class="paragraph"><p>Beware of the following caveats and limitations when using Flying Passenger:</p></div>
<div class="ulist"><ul>
<li>
<p>
The Nginx executable <strong>must</strong> be compiled with the same version of Phusion Passenger as the Flying Passenger daemon. Failing to meet this requirement may result in cryptic errors, or may result in certain features not working, until you’ve fixed the situation. When upgrading Phusion Passenger, you must restart both Nginx and the Flying Passenger daemon.
</p>
</li>
<li>
<p>
The <a href="#PassengerRoot">passenger_root</a> directive has no effect. When using Flying Passenger, you are not supposed to set <span class="monospaced">passenger_root</span>.
</p>
</li>
<li>
<p>
The Flying Passenger daemon is written in Ruby. It requires a Ruby interpreter with proper <span class="monospaced">Process#spawn</span> support. At the time of writing, all Ruby interpreters in existance satisfy this requirement, except for MRI Ruby 1.8 and JRuby. See <a href="#using_flying_passenger_with_mri_18_or_jruby">Using Flying Passenger with MRI 1.8 or JRuby</a> for more information.
</p>
</li>
<li>
<p>
When you add a new application to the web server configuration, Flying Passenger will automatically pick up the application’s settings and spawn this new application upon the first request to it. However it is not capable of automatically starting the new app before a request has been sent to it (i.e. <a href="#PassengerPreStart">passenger_pre_start</a>-like behavior is not available in this case). As a workaround, you can send an HTTP request to your application after starting the daemon, which forces it to spawn application processes.
</p>
</li>
<li>
<p>
When you remove an application from the web server configuration, Flying Passenger will not detect the removal and will not shut down the associated application processes. Killing the application processes will also not help, because Flying Passenger will restart them per the (now-removed, but still in the Flying Passenger daemon’s memory) <a href="#PassengerMinInstances">passenger_min_instances</a> settings. At the moment, there are two ways to get rid of those processes:
</p>
<div class="ulist"><ul>
<li>
<p>
Before removing the application from the web server configuration, explicitly set its <span class="monospaced">passenger_min_instances</span> to 0. Next, send a request to it, which will cause the Flying Passenger daemon to take over the new <span class="monospaced">passenger_min_instances 0</span> option. You can then proceed with removing the application from the web server configuration, and restarting the web server. Finally, kill the PIDs associated to those application processes and remove the application configuration.
</p>
</li>
<li>
<p>
Restart the Flying Passenger daemon.
</p>
</li>
</ul></div>
</li>
</ul></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_x_sendfile_support"></span><h3 data-comment-topic="x-sendfile-support-1cgyykw" data-anchor="_x_sendfile_support">11.11. X-Sendfile support</h3>
<div class="paragraph"><p>Phusion Passenger does not provide X-Sendfile support by itself. Please install
<a href="http://tn123.ath.cx/mod_xsendfile/">mod_xsendfile</a> for X-Sendfile support.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_upload_progress"></span><h3 data-comment-topic="upload-progress-71cyl7" data-anchor="_upload_progress">11.12. Upload progress</h3>
<div class="paragraph"><p>Phusion Passenger does not provide upload progress support by itself. Please
try drogus’s <a href="http://github.com/drogus/apache-upload-progress-module/tree/master">
Apache upload progress module</a> instead.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_under_the_hood"></span><h2 data-comment-topic="under-the-hood-21ue5t" data-anchor="_under_the_hood">12. Under the hood</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger hides a lot of complexity for the end user (i.e. the web server
system administrator), but sometimes it is desirable to know what is going on.
This section describes a few things that Phusion Passenger does under the hood.</p></div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_page_caching_support"></span><h3 data-comment-topic="page-caching-support-kwq9b9" data-anchor="_page_caching_support">12.1. Page caching support</h3>
<div class="paragraph"><p>For each HTTP request, Phusion Passenger will automatically look for a corresponding
page cache file, and serve that if it exists. It does this by appending ".html" to
the filename that the URI normally maps to, and checking whether that file exists.
This check occurs after checking whether the original mapped filename exists (as part
of static asset serving). All this is done without the need for special mod_rewrite
rules.</p></div>
<div class="paragraph"><p>For example, suppose that the browser requests <em>/foo/bar</em>.</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Phusion Passenger will first check whether this URI maps to a static file, i.e.
whether the file <em>foo/bar</em> exists in the web application’s <em>public</em> directory.
If it does then Phusion Passenger will serve this file through the web server immediately.
</p>
</li>
<li>
<p>
If that doesn’t exist, then Phusion Passenger will check whether the file
<em>foo/bar.html</em> exists. If it does then Phusion Passenger will serve this file
through the web server immediately.
</p>
</li>
<li>
<p>
If <em>foo/bar.html</em> doesn’t exist either, then Phusion Passenger will forward the
request to the underlying web application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>Note that Phusion Passenger’s page caching support doesn’t work if your web
application uses a non-standard page cache directory, i.e. if it doesn’t cache to
the <em>public</em> directory. In that case you’ll need to use mod_rewrite to serve such
page cache files.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="relationship_with_ruby"></span><h3 data-comment-topic="phusion-passenger-and-its-relationship-with-ruby-1eq08ff" data-anchor="relationship_with_ruby">12.2. Phusion Passenger and its relationship with Ruby</h3>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_how_ruby_is_used"></span><h4 data-comment-topic="how-ruby-is-used-14r83nr" data-anchor="_how_ruby_is_used">12.2.1. How Ruby is used</h4>
<div class="paragraph"><p>Phusion Passenger’s core is written in C++ for performance and memory efficiency. It supports web applications written in any language. Phusion Passenger requires Ruby, its usage of Ruby is minimal in order to maximize performance and to minimize memory usage.</p></div>
<div class="ulist"><ul>
<li>
<p>
Phusion Passenger’s installer, build system and administration tools are written in Ruby.
</p>
</li>
<li>
<p>
Certain internally used tools, such as the crash handler (which generates a backtrace in case Phusion Passenger crash) and the prespawn script (used to implement
<a href="#PassengerPreStart">PassengerPreStart</a>)
are written in Ruby as well.
</p>
</li>
<li>
<p>
Ruby web application support is implemented in Ruby.
</p>
</li>
<li>
<p>
If you use <a href="#flying_passenger">Flying Passenger</a>, then the Flying Passenger daemon is written in Ruby. The daemon is a small (less than 500 lines of code) and offloads most tasks to the C++ core.
</p>
</li>
<li>
<p>
If you use <a href="Users%20guide%20Standalone.html">Phusion Passenger Standalone</a>, then the frontend (the <span class="monospaced">passenger</span> command) is written in Ruby. The frontend is small (less than 1500 lines of code) and offloads most tasks to the C++ core.
</p>
</li>
</ul></div>
<div class="paragraph"><p>Other than the aforementioned aspects, Phusion Passenger does not use Ruby during normal operation. For example, if you run Python WSGI web applications on Phusion Passenger, then there will be (almost) no Ruby code running on the system.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_when_the_system_has_multiple_ruby_interpreters"></span><h4 data-comment-topic="when-the-system-has-multiple-ruby-interpreters-10tm1fq" data-anchor="_when_the_system_has_multiple_ruby_interpreters">12.2.2. When the system has multiple Ruby interpreters</h4>
<div class="paragraph"><p>Phusion Passenger may be installed with any Ruby interpreter. Once installed, you can run Phusion Passenger’s Ruby parts under any Ruby interpreter you want, even if that Ruby interpreter was not the one you originally installed Phusion Passenger with.</p></div>
<div class="paragraph"><p>The reason for this is that Phusion Passenger does not dynamically link to Ruby: Phusion Passenger uses Ruby entirely out-of-process. Thus you can switch to any Ruby interpreter you want during runtime, without recompiling Phusion Passenger, and without worrying about what Ruby you used to install Phusion Passenger.</p></div>
<div class="paragraph"><p>Phusion Passenger is also capable of running Ruby web applications under any Ruby interpreter you want. So it is not important which Ruby you use to install Phusion Passenger: it will work regardless. Please refer to the documentation for the
<a href="#PassengerRuby">PassengerRuby</a>
directive to learn how run different web applications under different Ruby interpreters.</p></div>
<div class="paragraph">
<div class="title">Caveat: RVM and RVM gemsets</div>
<p>There is however one caveat if you happen to be using RVM or RVM gemsets. When you <span class="monospaced">gem install</span> Phusion Passenger using RVM, then RVM will install Phusion Passenger into the <strong>currently active RVM Ruby and gemset</strong>. This means that Phusion Passenger commands - such as <span class="monospaced">passenger</span>, <span class="monospaced">passenger-install-xxx-module</span> and <span class="monospaced">passenger-status</span> - are available in that same RVM Ruby and gemset only. When you switch Ruby interpreter, or when you switch gemset, the Phusion Passenger commands will no longer be available, and you will get a <span class="monospaced">command not found</span> error. Here’s an example which demonstrates the problem.</p>
</div>
<div class="listingblock">
<div class="title">"Command not found" problem demonstration</div>
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-style: italic"><span style="color: #9A1900">## Install Phusion Passenger (open source edition) using Ruby 1.9.3</span></span>
<span style="font-style: italic"><span style="color: #9A1900">## and the 'business' gemset</span></span>
$ rvm use <span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>
Using /home/phusion<span style="color: #990000">/.</span>rvm/gems/ruby-<span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>-p<span style="color: #993399">429</span>
$ rvm gemset create business
$ rvm gemset use business
Using ruby-<span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>-p<span style="color: #993399">429</span> with gemset business
$ curl -O https<span style="color: #990000">:</span>//s<span style="color: #993399">3</span><span style="color: #990000">.</span>amazonaws<span style="color: #990000">.</span>com/phusion-passenger/releases/gem_bootstrap<span style="color: #990000">.</span>sh
$ <span style="font-weight: bold"><span style="color: #0000FF">eval</span></span> <span style="color: #FF0000">"`sh gem_bootstrap.sh`"</span>
$ gem install passenger
<span style="font-style: italic"><span style="color: #9A1900">## Verify that passenger works</span></span>
$ passenger --version
Phusion Passenger version <span style="color: #993399">4.0</span><span style="color: #990000">.</span><span style="color: #993399">14</span>
<span style="font-style: italic"><span style="color: #9A1900">## Switch to a different RVM gemset. You will get a `command not found`</span></span>
$ rvm gemset use default
Using ruby-<span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>-p<span style="color: #993399">429</span> with gemset default
$ passenger --version
bash<span style="color: #990000">:</span> passenger<span style="color: #990000">:</span> <span style="font-weight: bold"><span style="color: #0000FF">command</span></span> not found
<span style="font-style: italic"><span style="color: #9A1900">## Switch to a different Ruby interpreter. You will also get</span></span>
<span style="font-style: italic"><span style="color: #9A1900">## a `command not found`</span></span>
$ rvm use <span style="color: #993399">2.0</span><span style="color: #990000">.</span><span style="color: #993399">0</span>
Using /home/phusion<span style="color: #990000">/.</span>rvm/gems/ruby-<span style="color: #993399">2.0</span><span style="color: #990000">.</span><span style="color: #993399">0</span>-p<span style="color: #993399">195</span>
$ passenger --version
bash<span style="color: #990000">:</span> passenger<span style="color: #990000">:</span> <span style="font-weight: bold"><span style="color: #0000FF">command</span></span> not found
<span style="font-style: italic"><span style="color: #9A1900">## Switch back to the Ruby and gemset that you installed Phusion</span></span>
<span style="font-style: italic"><span style="color: #9A1900">## Passenger with, and verify that it works again</span></span>
$ rvm use <span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>
Using /home/phusion<span style="color: #990000">/.</span>rvm/gems/ruby-<span style="color: #993399">2.0</span><span style="color: #990000">.</span><span style="color: #993399">0</span>-p<span style="color: #993399">195</span>
$ rvm gemset use business
Using ruby-<span style="color: #993399">1.9</span><span style="color: #990000">.</span><span style="color: #993399">3</span>-p<span style="color: #993399">429</span> with gemset business
$ passenger --version
Phusion Passenger version <span style="color: #993399">4.0</span><span style="color: #990000">.</span><span style="color: #993399">14</span></tt></pre>
</div>
</div>
<div class="paragraph">
<div class="title">Solutions</div>
<p>There are several ways to solve this problem:</p>
</div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Permanently add Phusion Passenger’s command directory to your PATH, so that your shell can always find them even when you switch RVM Ruby or gemset. If you don’t know what PATH means, please read <a href="#about_environment_variable">About environment variables</a> first.
</p>
<div class="paragraph"><p>The drawback is that you have to redo this every time you upgrade Phusion Passenger, because the Phusion Passenger directory filename is dependent on the version number.</p></div>
<div class="paragraph"><p>First, identify the location of the Phusion Passenger command directory, like this:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ echo `passenger-config --root`/bin
/home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin</pre>
</div>
</div>
<div class="paragraph"><p>Next, add the directory that you’ve found to your current shell’s PATH:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ export PATH=/home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin:$PATH</pre>
</div>
</div>
<div class="paragraph"><p>Finally, make the change permanent by appending the above command to your bash startup file:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>$ echo 'export PATH=/home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin:$PATH' >> ~/.bashrc</pre>
</div>
</div>
</li>
<li>
<p>
Switch back to the RVM Ruby and gemset that you installed Phusion Passenger with, before running any Phusion Passenger command.
</p>
</li>
<li>
<p>
Prepend any Phusion Passenger command with <span class="monospaced">rvm-exec RUBY_NAME@GEMSET_NAME ruby -S</span>. If the relevant Phusion Passenger command also needs root privileges, then prepend <span class="monospaced">rvmsudo</span> before that. For example:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>rvm-exec 1.9.3@business ruby -S passenger --version
rvmsudo rvm-exec 1.9.3@business ruby -S passenger-install-apache2-module</pre>
</div>
</div>
</li>
</ol></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_static_assets_serving"></span><h3 data-comment-topic="static-assets-serving-wo2d9v" data-anchor="_static_assets_serving">12.3. Static assets serving</h3>
<div class="paragraph"><p>Phusion Passenger accelerates serving of static files. This means that, if an URI
maps to a file that exists, then Phusion Passenger will let Apache serve that file
directly, without hitting the web application.</p></div>
<div class="paragraph"><p>Phusion Passenger does all this without the need for any mod_rewrite rules. People
who are switching from an old Mongrel-based setup might have mod_rewrite rules such
as these:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre># Check whether this request has a corresponding file; if that
# exists, let Apache serve it, otherwise forward the request to
# Mongrel.
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ balancer://mongrel%{REQUEST_URI} [P,QSA,L]</pre>
</div>
</div>
<div class="paragraph"><p>These kind of mod_rewrite rules are no longer required, and you can safely remove
them.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="application_detection"></span><h3 data-comment-topic="how-phusion-passenger-detects-whether-a-virtual-host-is-a-web-application-179mp8m" data-anchor="application_detection">12.4. How Phusion Passenger detects whether a virtual host is a web application</h3>
<div class="paragraph"><p>After you’ve read the deployment instructions you might wonder how Phusion Passenger
knows that the DocumentRoot points to a web application that Phusion Passenger is
able to serve, and how it knows what kind of web application it is (e.g. Rails or Rack).</p></div>
<div class="paragraph"><p>Phusion Passenger checks whether the virtual host is a Rails application by checking
whether the following file exists:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>dirname(DocumentRoot) + "/config/environment.rb"</pre>
</div>
</div>
<div class="paragraph"><p>If you’re not a programmer and don’t understand the above pseudo-code snippet, it means
that Phusion Passenger will:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Extract the parent directory filename from the value of the DocumentRoot directory.
</p>
</li>
<li>
<p>
Append the text "/config/environment.rb" to the result, and check whether the resulting
filename exists.
</p>
</li>
</ol></div>
<div class="paragraph"><p>So suppose that your document root is <em>/webapps/foo/public</em>. Phusion Passenger will check
whether the file <em>/webapps/foo/config/environment.rb</em> exists.</p></div>
<div class="paragraph"><p>Note that Phusion Passenger does <strong>not</strong> resolve any symlinks in the document root path by
default since version 2.2.0 — in contrast to versions earlier than 2.2.0, which do resolve
symlinks.
So for example, suppose that your DocumentRoot points to <em>/home/www/example.com</em>, which in
turn is a symlink to <em>/webapps/example.com/public</em>. In versions earlier than 2.2.0, Phusion
Passenger will check whether <em>/webapps/example.com/config/environment.rb</em> exists because it
resolves all symlinks. Phusion Passenger 2.2.0 and later however will check for
<em>/home/www/config/environment.rb</em>. This file of course doesn’t exist, and as a result Phusion
Passenger will not activate itself for this virtual host, and you’ll most likely see an Apache
mod_dirindex directory listing.</p></div>
<div class="paragraph"><p>If you need the old symlink-resolving behavior for whatever reason, then you can turn on
<a href="#PassengerResolveSymlinksInDocumentRoot">PassengerResolveSymlinksInDocumentRoot</a>.</p></div>
<div class="paragraph"><p>Another way to solve this situation is to explicitly tell Phusion Passenger what the
correct application root is through the <a href="#PassengerAppRoot">PassengerAppRoot</a> configuration
directive.</p></div>
<div class="paragraph"><p>Autodetection of Rack applications happens through the same mechanism, exception that
Phusion Passenger will look for <em>config.ru</em> instead of <em>config/environment.rb</em>.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_appendix_a_about_this_document"></span><h2 data-comment-topic="appendix-a-about-this-document-103toqs" data-anchor="_appendix_a_about_this_document">13. Appendix A: About this document</h2>
<div class="sectionbody">
<div class="paragraph"><p>The text of this document is licensed under the
<a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-Share Alike 3.0 Unported License</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://creativecommons.org/licenses/by-sa/3.0/">
<img src="images/by_sa.png" alt="images/by_sa.png">
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is brought to you by <a href="http://www.phusion.nl/">Phusion</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png">
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.</p></div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_appendix_b_terminology"></span><h2 data-comment-topic="appendix-b-terminology-h4eaf4" data-anchor="_appendix_b_terminology">14. Appendix B: Terminology</h2>
<div class="sectionbody">
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="application_root"></span><h3 data-comment-topic="application-root-otx6xf" data-anchor="application_root">14.1. Application root</h3>
<div class="paragraph"><p>The root directory of an application that’s served by Phusion Passenger.</p></div>
<div class="paragraph"><p>In case of Ruby on Rails applications, this is the directory that contains
<em>Rakefile</em>, <em>app/</em>, <em>config/</em>, <em>public/</em>, etc. In other words, the directory
pointed to by <span class="monospaced">RAILS_ROOT</span>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/apps/foo/ <------ This is the Rails application's application root!
|
+- app/
| |
| +- controllers/
| |
| +- models/
| |
| +- views/
|
+- config/
| |
| +- environment.rb
| |
| +- ...
|
+- public/
| |
| +- ...
|
+- ...</pre>
</div>
</div>
<div class="paragraph"><p>In case of Rack applications, this is the directory that contains <em>config.ru</em>.
For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/apps/bar/ <----- This is the Rack application's application root!
|
+- public/
| |
| +- ...
|
+- config.ru
|
+- ...</pre>
</div>
</div>
<div class="paragraph"><p>In case of Python (WSGI) applications, this is the directory that contains
<em>passenger_wsgi.py</em>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>/apps/baz/ <----- This is the WSGI application's application root!
|
+- public/
| |
| +- ...
|
+- passenger_wsgi.py
|
+- ...</pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="idle_process"></span><h3 data-comment-topic="idle-process-potb6g" data-anchor="idle_process">14.2. Idle process</h3>
<div class="paragraph"><p>An "idle process" refers to a process that hasn’t processed any requests for a while.</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="inactive_process"></span><h3 data-comment-topic="inactive-process-16gjv2e" data-anchor="inactive_process">14.3. Inactive process</h3>
<div class="paragraph"><p>An "inactive process" refers to a process that’s current not processing any requests. An idle process is always inactive, but an inactive process is not always considered idle.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="spawning_methods_explained"></span><h2 data-comment-topic="appendix-c-spawning-methods-explained-owghi9" data-anchor="spawning_methods_explained">15. Appendix C: Spawning methods explained</h2>
<div class="sectionbody">
<div class="paragraph"><p>At its core, Phusion Passenger is an HTTP proxy and process manager. It spawns
Ruby on Rails/Rack/WSGI worker processes (which may also be referred to as
<em>backend processes</em>), and forwards incoming HTTP request to one of the worker
processes.</p></div>
<div class="paragraph"><p>While this may sound simple, there’s not just one way to spawn worker processes.
Let’s go over the different spawning methods. For simplicity’s sake, let’s
assume that we’re only talking about Ruby on Rails applications.</p></div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_most_straightforward_and_traditional_way_direct_spawning"></span><h3 data-comment-topic="the-most-straightforward-and-traditional-way-conservative-spawning-1ybbli2" data-anchor="_the_most_straightforward_and_traditional_way_direct_spawning">15.1. The most straightforward and traditional way: direct spawning</h3>
<div class="paragraph"><p>Phusion Passenger could create a new Ruby process, which will then load the
Rails application along with the entire Rails framework. This process will then
enter an request handling main loop.</p></div>
<div class="paragraph"><p>This is the most straightforward way to spawn worker processes. If you’re
familiar with the Mongrel application server, then this approach is exactly
what mongrel_cluster performs: it creates N worker processes, each which loads
a full copy of the Rails application and the Rails framework in memory. The Thin
application server employs pretty much the same approach.</p></div>
<div class="paragraph"><p>Note that Phusion Passenger’s version of direct spawning differs slightly
from mongrel_cluster. Mongrel_cluster creates entirely new Ruby processes. In
programmers jargon, mongrel_cluster creates new Ruby processes by forking the
current process and exec()-ing a new Ruby interpreter. Phusion Passenger on the
other hand creates processes that reuse the already loaded Ruby interpreter. In
programmers jargon, Phusion Passenger calls fork(), but not exec().</p></div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_smart_spawning_method"></span><h3 data-comment-topic="the-smart-spawning-method-1cvu9dd" data-anchor="_the_smart_spawning_method">15.2. The smart spawning method</h3>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">Smart spawning is supported for all Ruby applications but not for WSGI applications.</td>
</tr></table>
</div>
<div class="paragraph"><p>While direct spawning works well, it’s not as efficient as it could be
because each worker process has its own private copy of the Rails application
as well as the Rails framework. This wastes memory as well as startup time.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/direct_spawning.png" alt="Worker processes and direct spawning">
</span><br>
<em>Figure: Worker processes and direct spawning. Each worker process has its
own private copy of the application code and Rails framework code.</em></p></div>
<div class="paragraph"><p>It is possible to make the different worker processes share the memory occupied
by application and Rails framework code, by utilizing so-called
copy-on-write semantics of the virtual memory system on modern operating
systems. As a side effect, the startup time is also reduced. This is technique
is exploited by Phusion Passenger’s <em>smart</em> spawn method.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_how_it_works"></span><h4 data-comment-topic="how-it-works-672zja" data-anchor="_how_it_works">15.2.1. How it works</h4>
<div class="paragraph"><p>When the <em>smart</em> spawn method is being used, Phusion Passenger will first
create a so-called <em>ApplicationSpawner server</em> process. This process loads the
entire Rails application along with the Rails framework, by loading
<em>environment.rb</em>. Then, whenever Phusion Passenger needs a new worker process,
it will instruct the ApplicationSpawner server to do so. The ApplicationSpawner
server will create a worker new process
that reuses the already loaded Rails application/framework. Creating a worker
process through an already running ApplicationSpawner server is very fast, about
10 times faster than loading the Rails application/framework from scratch. If
the Ruby interpreter is copy-on-write friendly (that is, if you’re running
<a href="#reducing_memory_usage">Ruby Enterprise Edition</a>) then all created worker
processes will share as much common
memory as possible. That is, they will all share the same application and Rails
framework code.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/smart.png" alt="images/smart.png">
</span><br>
<em>Figure: Worker processes and the smart spawn method. All worker processes,
as well as the ApplicationSpawner, share the same application code and Rails
framework code.</em></p></div>
<div class="paragraph"><p>The <em>smart</em> method allows different worker processes that belong to the same
application to share memory.</p></div>
<div class="paragraph"><p>Notes:</p></div>
<div class="ulist"><ul>
<li>
<p>
Vendored Rails frameworks cannot be shared by different applications, even if
both vendored Rails frameworks are the same version. So for efficiency reasons
we don’t recommend vendoring Rails.
</p>
</li>
<li>
<p>
ApplicationSpawner servers have an idle timeout just like worker processes.
If an ApplicationSpawner/FrameworkSpawner server hasn’t been instructed to do
anything for a while, it will be shutdown in order to conserve memory. This
idle timeout is configurable.
</p>
</li>
</ul></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_summary_of_benefits"></span><h4 data-comment-topic="summary-of-benefits-1yrihfb" data-anchor="_summary_of_benefits">15.2.2. Summary of benefits</h4>
<div class="paragraph"><p>Suppose that Phusion Passenger needs a new worker process for an application
that uses Rails 2.2.1.</p></div>
<div class="paragraph"><p>If the <em>smart</em> spawning method is used, and an ApplicationSpawner server
for this application is already running, then worker process creation time is
about 10 times faster than direct spawning. This worker process will also
share application and Rails framework code memory with the ApplicationSpawner
server and the worker processes that had been spawned by this ApplicationSpawner
server.</p></div>
<div class="paragraph"><p>In practice, the smart spawning method could mean a memory saving of about 33%,
assuming that your Ruby interpreter is <a href="#reducing_memory_usage">copy-on-write friendly</a>.</p></div>
<div class="paragraph"><p>Of course, smart spawning is not without gotchas. But if you understand the
gotchas you can easily reap the benefits of smart spawning.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_smart_spawning_gotcha_1_unintentional_file_descriptor_sharing"></span><h3 data-comment-topic="smart-spawning-gotcha-1-unintentional-file-descriptor-sharing-z1y55l" data-anchor="_smart_spawning_gotcha_1_unintentional_file_descriptor_sharing">15.3. Smart spawning gotcha #1: unintentional file descriptor sharing</h3>
<div class="paragraph"><p>Because worker processes are created by forking from an ApplicationSpawner
server, it will share all file descriptors that are opened by the
ApplicationSpawner server. (This is part of the semantics of the Unix
<em>fork()</em> system call. You might want to Google it if you’re not familiar with
it.) A file descriptor is a handle which can be an opened file, an opened socket
connection, a pipe, etc. If different worker processes write to such a file
descriptor at the same time, then their write calls will be interleaved, which
may potentially cause problems.</p></div>
<div class="paragraph"><p>The problem commonly involves socket connections that are unintentionally being
shared. You can fix it by closing and reestablishing the connection when Phusion
Passenger is creating a new worker process. Phusion Passenger provides the API
call <span class="monospaced">PhusionPassenger.on_event(:starting_worker_process)</span> to do so. So you
could insert the following code in your <em>environment.rb</em>:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to reestablish socket connections here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in direct spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre>
</div>
</div>
<div class="paragraph"><p>Note that Phusion Passenger automatically reestablishes the connection to the
database upon creating a new worker process, which is why you normally do not
encounter any database issues when using smart spawning mode.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_example_1_memcached_connection_sharing_harmful"></span><h4 data-comment-topic="example-1-memcached-connection-sharing-harmful--c71wqw" data-anchor="_example_1_memcached_connection_sharing_harmful">15.3.1. Example 1: Memcached connection sharing (harmful)</h4>
<div class="paragraph"><p>Suppose we have a Rails application that connects to a Memcached server in
<em>environment.rb</em>. This causes the ApplicationSpawner to have a socket connection
(file descriptor) to the Memcached server, as shown in the following figure:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>+--------------------+
| ApplicationSpawner |-----------[Memcached server]
+--------------------+</pre>
</div>
</div>
<div class="paragraph"><p>Phusion Passenger then proceeds with creating a new Rails worker process, which
is to process incoming HTTP requests. The result will look like this:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/
+--------------------+</pre>
</div>
</div>
<div class="paragraph"><p>Since a <em>fork()</em> makes a (virtual) complete copy of a process, all its file
descriptors will be copied as well. What we see here is that ApplicationSpawner
and Worker process 1 both share the same connection to Memcached.</p></div>
<div class="paragraph"><p>Now supposed that your site gets Slashdotted and Phusion Passenger needs to
spawn another worker process. It does so by forking ApplicationSpawner. The
result is now as follows:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/|
+--------------------+ |
|
+--------------------+ |
| Worker process 2 |-----/
+--------------------+</pre>
</div>
</div>
<div class="paragraph"><p>As you can see, Worker process 1 and Worker process 2 have the same Memcached
connection.</p></div>
<div class="paragraph"><p>Suppose that users Joe and Jane visit your website at the same time. Joe’s
request is handled by Worker process 1, and Jane’s request is handled by Worker
process 2. Both worker processes want to fetch something from Memcached. Suppose
that in order to do that, both handlers need to send a "FETCH" command to Memcached.</p></div>
<div class="paragraph"><p>But suppose that, after worker process 1 having only sent "FE", a context switch
occurs, and worker process 2 starts sending a "FETCH" command to Memcached as
well. If worker process 2 succeeds in sending only one bye, <em>F</em>, then Memcached
will receive a command which begins with "FEF", a command that it does not
recognize. In other words: the data from both handlers get interleaved. And thus
Memcached is forced to handle this as an error.</p></div>
<div class="paragraph"><p>This problem can be solved by reestablishing the connection to Memcached after forking:</p></div>
<div class="literalblock">
<div class="content monospaced">
<pre>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ | |
| |
+--------------------+ | |
| Worker process 1 |-----/| |
+--------------------+ | | <--- created this
X | new
| connection
X <-- closed this |
+--------------------+ | old |
| Worker process 2 |-----/ connection |
+--------------------+ |
| |
+-------------------------------------+</pre>
</div>
</div>
<div class="paragraph"><p>Worker process 2 now has its own, separate communication channel with Memcached.
The code in <em>environment.rb</em> looks like this:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
reestablish_connection_to_memcached
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in direct spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_example_2_log_file_sharing_not_harmful"></span><h4 data-comment-topic="example-2-log-file-sharing-not-harmful--1p2yuol" data-anchor="_example_2_log_file_sharing_not_harmful">15.3.2. Example 2: Log file sharing (not harmful)</h4>
<div class="paragraph"><p>There are also cases in which unintentional file descriptor sharing is not harmful.
One such case is log file file descriptor sharing. Even if two processes write
to the log file at the same time, the worst thing that can happen is that the
data in the log file is interleaved.</p></div>
<div class="paragraph"><p>To guarantee that the data written to the log file is never interleaved, you
must synchronize write access via an inter-process synchronization mechanism,
such as file locks. Reopening the log file, like you would have done in the
Memcached example, doesn’t help.</p></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_smart_spawning_gotcha_2_the_need_to_revive_threads"></span><h3 data-comment-topic="smart-spawning-gotcha-2-the-need-to-revive-threads-1k6cj7d" data-anchor="_smart_spawning_gotcha_2_the_need_to_revive_threads">15.4. Smart spawning gotcha #2: the need to revive threads</h3>
<div class="paragraph"><p>Another part of the <em>fork()</em> system call’s semantics is the fact that threads
disappear after a fork call. So if you’ve created any threads in environment.rb,
then those threads will no longer be running in newly created worker process.
You need to revive them when a new worker process is created. Use the
<span class="monospaced">:starting_worker_process</span> event that Phusion Passenger provides, like this:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to revive threads here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in direct spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_smart_spawning_gotcha_3_code_load_order"></span><h3 data-comment-topic="smart-spawning-gotcha-3-code-load-order-nkotiy" data-anchor="_smart_spawning_gotcha_3_code_load_order">15.5. Smart spawning gotcha #3: code load order</h3>
<div class="paragraph"><p>This gotcha is only applicable to the <em>smart</em> spawn method, not the <em>smart-lv2</em>
spawn method.</p></div>
<div class="paragraph"><p>If your application expects the Rails framework to be not loaded during the
beginning of <em>environment.rb</em>, then it can cause problems when an
ApplicationSpawner is created from a FrameworkSpawner, which already has the
Rails framework loaded. The most common case is when applications try to patch
Rails by dropping a modified file that has the same name as Rails’s own file,
in a path that comes earlier in the Ruby search path.</p></div>
<div class="paragraph"><p>For example, suppose that we have an application which has a patched version
of <em>active_record/base.rb</em> located in <em>RAILS_ROOT/lib/patches</em>, and
<em>RAILS_ROOT/lib/patches</em> comes first in the Ruby load path. When conservative
spawning is used, the patched version of <em>base.rb</em> is properly loaded. When
<em>smart</em> (not <em>smart-lv2</em>) spawning is used, the original <em>base.rb</em> is used
because it was already loaded, so a subsequent <span class="monospaced">require "active_record/base"</span>
has no effect.</p></div>
</div>
</div>
</div>
<div class="sect1">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="about_environment_variables"></span><h2 data-comment-topic="appendix-d-about-environment-variables-1lebv1u" data-anchor="about_environment_variables">16. Appendix D: About environment variables</h2>
<div class="sectionbody">
<div class="paragraph"><p>The Phusion Passenger compilation process can be customized with environment variables.</p></div>
<div class="paragraph"><p>Environment variables are named values that affect how the system works. For example they tell the system where to look for commands (the <span class="monospaced">PATH</span> variable) or where to look for libraries (<span class="monospaced">LD_LIBRARY_PATH</span>). Their names are often in all-uppercase. Sometimes people refer to an environment variable with a dollar sign <span class="monospaced">$</span> in front, but that’s the same thing: when people say "the $PATH environment variable" they mean "the PATH environment variable". This is because the dollar sign <span class="monospaced">$</span> is a shell syntax for refering to an environment variable, as you will learn later.</p></div>
<div class="paragraph"><p>Environment variables are set on a <strong>per-process</strong> basis, but they are <strong>inherited</strong> by child processes. This means that if you set environment variables in process A, another already running process B will not see these new environment variables. But if A spawns a child process C, then C will have all environment variables that A had. If you once again change the environment variables in A, then C will not see the changes.</p></div>
<div class="paragraph"><p>The per-process nature of environment variables some implications. When you set environment variables in your <span class="monospaced">bashrc</span> or other bash startup files…</p></div>
<div class="ulist"><ul>
<li>
<p>
…only newly spawned bash shells see them.
</p>
</li>
<li>
<p>
…the web server usually does not see them, because the web server tends to be started from init scripts, not from bash.
</p>
</li>
<li>
<p>
…cron jobs do not see them, because cron jobs' environment variables are entirely dictated by their crontabs.
</p>
</li>
</ul></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">Because this chapter is meant for beginners, it assumes that the reader uses the bash shell. This chapter does not describe instructions for zsh, csh or other shells. We assume that users of other shells are familiar with the Bourne shell syntax, and know how to apply the instructions in this chapter in their shells' native syntaxes.</td>
</tr></table>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_working_with_environment_variables"></span><h3 data-comment-topic="working-with-environment-variables-85e6aa" data-anchor="_working_with_environment_variables">16.1. Working with environment variables</h3>
<div class="paragraph"><p>You can see all environment variables in your shell by running the following command:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>env</tt></pre>
</div>
</div>
<div class="paragraph"><p>You can set an evironment variable with the syntax <span class="monospaced">export <NAME>=<VALUE></span>. For example, to set the <span class="monospaced">APXS2</span> variable to the value <span class="monospaced">/usr/sbin/apxs2</span>:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">APXS2</span><span style="color: #990000">=</span>/usr/sbin/apxs<span style="color: #993399">2</span></tt></pre>
</div>
</div>
<div class="paragraph"><p>Any process that you run from your shell from that point on will have said environment variable:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">APXS2</span><span style="color: #990000">=</span>/usr/sbin/apxs<span style="color: #993399">2</span>
ruby -e <span style="color: #FF0000">'p ENV["APXS2"]'</span>
<span style="font-style: italic"><span style="color: #9A1900"># => "/usr/sbin/apxs2"</span></span></tt></pre>
</div>
</div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">
<div class="title">The "export" keyword is important</div>
<div class="paragraph"><p>You <strong>must</strong> set the <span class="monospaced">export</span> keyword. If you omit the <span class="monospaced">export</span> keyword then the environment variable will not be visible to other processes:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">APXS2</span><span style="color: #990000">=</span>/usr/sbin/apxs<span style="color: #993399">2</span>
ruby -e <span style="color: #FF0000">'p ENV["APXS2"]'</span>
<span style="font-style: italic"><span style="color: #9A1900"># => nil</span></span></tt></pre>
</div>
</div>
</td>
</tr></table>
</div>
<div class="paragraph"><p>You can reference an environment variable in your shell by typing the <span class="monospaced">$</span> sign followed by the environment variable’s name. For example, to see the value of the <span class="monospaced">PATH</span> variable:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>echo <span style="color: #009900">$PATH</span></tt></pre>
</div>
</div>
<div class="paragraph"><p>You can also use this trick to extend the value of an environment variable:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">PATH</span><span style="color: #990000">=</span>/usr/bin
<span style="font-style: italic"><span style="color: #9A1900"># Prepends '/opt/local/bin', so that it becomes /opt/local/bin:/usr/bin</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">PATH</span><span style="color: #990000">=</span>/opt/local/bin<span style="color: #990000">:</span><span style="color: #009900">$PATH</span>
<span style="font-style: italic"><span style="color: #9A1900"># Appends '/usr/local/bin', so that it becomes /opt/local/bin:/usr/bin:/usr/local/bin</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">PATH</span><span style="color: #990000">=</span><span style="color: #009900">$PATH</span><span style="color: #990000">:</span>/usr/local/bin</tt></pre>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_the_path_environment_variable"></span><h3 data-comment-topic="the-path-environment-variable-p8e32r" data-anchor="_the_path_environment_variable">16.2. The PATH environment variable</h3>
<div class="paragraph"><p>The <span class="monospaced">PATH</span> environment variable dictates where the system looks for command. It is a colon-separated list of directories. If you get a "command not found" error while you know that the command is installed, then setting <span class="monospaced">PATH</span> will help. For example suppose that the command <span class="monospaced">frobnicator</span> is in <span class="monospaced">/opt/local/bin</span>:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>user@localhost bash$ frobnicator
bash<span style="color: #990000">:</span> frobnicator<span style="color: #990000">:</span> <span style="font-weight: bold"><span style="color: #0000FF">command</span></span> not found</tt></pre>
</div>
</div>
<div class="paragraph"><p>We verify that <span class="monospaced">/opt/local/bin</span> is not in <span class="monospaced">PATH</span>:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>user@localhost bash$ echo <span style="color: #009900">$PATH</span>
/bin<span style="color: #990000">:</span>/usr/bin<span style="color: #990000">:</span>/usr/local/bin</tt></pre>
</div>
</div>
<div class="paragraph"><p>We can run <span class="monospaced">frobnicator</span> through it’s full path…</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>user@localhost bash$ /opt/local/bin/frobnicator
<span style="font-style: italic"><span style="color: #9A1900"># => success!</span></span></tt></pre>
</div>
</div>
<div class="paragraph"><p>…or we can add <span class="monospaced">/opt/local/bin</span> to <span class="monospaced">PATH</span>.</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>user@localhost bash$ <span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">PATH</span><span style="color: #990000">=</span><span style="color: #009900">$PATH</span><span style="color: #990000">:</span>/opt/local/bin
user@localhost bash$ frobnicator
<span style="font-style: italic"><span style="color: #9A1900"># => success!</span></span></tt></pre>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_adding_phusion_passenger_8217_s_administration_tools_to_path"></span><h4 data-comment-topic="adding-phusion-passenger-s-administration-tools-to-path-xwppud" data-anchor="_adding_phusion_passenger_8217_s_administration_tools_to_path">16.2.1. Adding Phusion Passenger’s administration tools to PATH</h4>
<div class="paragraph"><p>If you get a "command not found" error when invoking one of the Phusion Passenger administration tools (e.g. <span class="monospaced">passenger-status</span> or <span class="monospaced">passenger-memory-stats</span> then that means the tools are not in <span class="monospaced">PATH</span>, so you need to add them.</p></div>
<div class="ulist"><ul>
<li>
<p>
If you <a href="#rubygems_generic_install">installed Phusion Passenger with RubyGems</a>, then the tools are in your RubyGems executable path. You can view the gem path using the command <span class="monospaced">gem env</span>:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.15
- RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [i686-darwin10.8.0]
- INSTALLATION DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/ruby-enterprise-1.8.7-2010.01/bin/ruby
- EXECUTABLE DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.01/bin <--------- !!
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8
- /Users/hongli/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- REMOTE SOURCES:
- http://rubygems.org/</pre>
</div>
</div>
<div class="paragraph"><p>As you can see, the RubyGems executable path in the example happens to be <span class="monospaced">/opt/ruby-enterprise-1.8.7-2010.01/bin</span>. So that directory must be added to <span class="monospaced">PATH</span>.</p></div>
</li>
<li>
<p>
If you <a href="#tarball_generic_install">installed Phusion Passenger using the tarball</a>, then the tools are in the <span class="monospaced">bin</span> subdirectory of the Phusion Passenger tarball directory that you extracted. For example, if you extracted <span class="monospaced">passenger-4.9.0.tar.gz</span> inside <span class="monospaced">/opt</span>, then the tools are located in <span class="monospaced">/opt/passenger-4.0.9/bin</span>. In that case, you need to add <span class="monospaced">/opt/passenger-4.0.9/bin</span> to your <span class="monospaced">PATH</span>.
</p>
</li>
<li>
<p>
If you installed Phusion Passenger using native OS packages, then some Phusion Passenger administration tools are in <span class="monospaced">/usr/bin</span>, while others are in <span class="monospaced">/usr/sbin</span>. If you are not logged in as root, then <span class="monospaced">/usr/sbin</span> may not be in <span class="monospaced">PATH</span>, which would explain why you get a "command not found" when trying to invoke some of the tools. You should <span class="monospaced">/usr/sbin</span> to <span class="monospaced">PATH</span>.
</p>
</li>
<li>
<p>
If you are unsure where your Phusion Passenger directory is then you can use the <span class="monospaced">find</span> command to look them up. Go to the root directory and invoke <span class="monospaced">find</span> with <span class="monospaced">sudo</span>:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre>$ cd /
$ sudo find . -name passenger-status
/usr/local/passenger/bin/passenger-status</pre>
</div>
</div>
<div class="paragraph"><p>In this example, the administration tools happen to be in <span class="monospaced">/usr/local/passenger/bin</span>, so you must add that to <span class="monospaced">PATH</span>.</p></div>
</li>
</ul></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">You may still get a "command not found" when invoking the tools through sudo, even after you’ve added the relevant directory to <span class="monospaced">PATH</span>. Please read <a href="#env_vars_and_sudo">Environment variables and sudo</a> to learn more.</td>
</tr></table>
</div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_making_environment_variables_permanent"></span><h3 data-comment-topic="making-environment-variables-permanent-13x0l4h" data-anchor="_making_environment_variables_permanent">16.3. Making environment variables permanent</h3>
<div class="paragraph"><p>When you exit your shell, the evironment variable changes are lost. There is no standard method to set environment variables system-wide, so you have to set them in different configuration files for different services.</p></div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_bash"></span><h4 data-comment-topic="bash-1pktn63" data-anchor="_bash">16.3.1. bash</h4>
<div class="paragraph"><p>To make environment variables permanent for future bash sessions <strong>for the current user</strong>, add them to your <span class="monospaced">~/.bashrc</span>:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>echo <span style="color: #FF0000">'export FOO=bar'</span> <span style="color: #990000">>></span> <span style="color: #990000">~/.</span>bashrc
echo <span style="color: #FF0000">'export PATH=/usr/local/bin:$PATH'</span> <span style="color: #990000">>></span> <span style="color: #990000">~/.</span>bashrc</tt></pre>
</div>
</div>
<div class="paragraph"><p>To make them permanent for future bash sessions <strong>for all users</strong>, add them to <span class="monospaced">/etc/bashrc</span>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">Depending on the system, the bashrc file may have a different filename. On Debian and Ubuntu, it’s <span class="monospaced">/etc/bash.bashrc</span>.</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_apache"></span><h4 data-comment-topic="apache-15zqjvi" data-anchor="_apache">16.3.2. Apache</h4>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">This subsection describes how to set environment variables on Apache itself, not on apps served through Phusion Passenger for Apache. The environment variables you set here will be passed to all apps, but you cannot customize them on a per-app basis. See also <a href="#env_vars_passenger_apps">Setting environment variables on Phusion Passenger-served apps</a>.</td>
</tr></table>
</div>
<div class="paragraph"><p>On Debian and Ubuntu, with an Apache installed through apt, Apache environment variables are defined in the file <span class="monospaced">/etc/apache2/envvars</span>. This is a shell script so environment variables must be specified with the shell syntax.</p></div>
<div class="paragraph"><p>On Red Hat, Fedora, CentOS and ScientificLinux, with an Apache installed through YUM, Apache environment variables are defined in <span class="monospaced">/etc/sysconfig/httpd</span>.</p></div>
<div class="paragraph"><p>On OS X they are defined in <span class="monospaced">/System/Library/LaunchDaemons/org.apache.httpd.plist</span>, as explained <a href="/System/Library/LaunchDaemons/org.apache.httpd.plist">here on Stack Overflow</a>.</p></div>
<div class="paragraph"><p>On other systems, or if you did not install Apache through the system’s package manager, the configuration file for environment variables is specific to the vendor that supplied Apache. There may not even be such a configuration file. You should contact the vendor for support.</p></div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_nginx"></span><h4 data-comment-topic="nginx-l7ztbb" data-anchor="_nginx">16.3.3. Nginx</h4>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">This subsection describes how to set environment variables on Nginx itself, not on apps served through Phusion Passenger for Nginx. The environment variables you set here will be passed to all apps, but you cannot customize them on a per-app basis. See also <a href="#env_vars_passenger_apps">Setting environment variables on Phusion Passenger-served apps</a>.</td>
</tr></table>
</div>
<div class="paragraph"><p>If you installed Nginx through <a href="#install_on_debian_ubuntu">the Debian or Ubuntu packages</a>, then you can define environment variables in <span class="monospaced">/etc/default/nginx</span>. This is a shell script so you must use the <span class="monospaced">export FOO=bar</span> syntax.</p></div>
<div class="paragraph"><p>Otherwise, environment variables are best set through the script which starts Nginx. For example, if you installed Nginx from source and you used
the Nginx init script described in the <a href="http://www.modrails.com/documentation/Users%20guide%20Nginx.html">Phusion Passenger Users Guide, Nginx version</a>,
then you should edit that script to define the environment variables. Those init scripts are regular shell scripts, so use the <span class="monospaced">export FOO=bar</span> syntax. Just make sure your set your environment variables before the script starts Nginx.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">Setting environment variables on Nginx has no effect on the <a href="#flying_passenger">Flying Passenger daemon</a> because the daemon is started seperately. You should set the environment variables in the shell right before starting the daemon.</td>
</tr></table>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="_cron"></span><h4 data-comment-topic="cron-1kjp7ck" data-anchor="_cron">16.3.4. cron</h4>
<div class="paragraph"><p>To make environment variables permanent for cron jobs, add those variables to the relevant crontab. But note that inside crontabs you cannot refer to existing environment variables with the <span class="monospaced">$</span> syntax because crontabs are not shell scripts. You have to specify the entire value.</p></div>
<div class="listingblock">
<div class="title">What to put in "crontab -e"</div>
<div class="content monospaced">
<pre># Environment variable definitions
FOO=bar
APXS2=/usr/sbin/apxs2
# **WRONG!** You cannot refer to existing variables with the `$` syntax!
PATH=/usr/bin:$PATH
# **WRONG!** You cannot use the 'export' keyword!
export PATH=/usr/bin:/usr/local/bin
# Correct:
PATH=/usr/bin:/usr/local/bin
# Jobs:
# m h dom mon dow command
* * * * * frobnicator</pre>
</div>
</div>
</div>
<div class="sect3">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="env_vars_passenger_apps"></span><h4 data-comment-topic="phusion-passenger-served-apps-478vyt" data-anchor="env_vars_passenger_apps">16.3.5. Phusion Passenger-served apps</h4>
<div class="paragraph"><p>You can pass environment variables to Phusion Passenger-served apps through various methods:</p></div>
<div class="ulist"><ul>
<li>
<p>
When running Apache, use the <span class="monospaced">PassEnv</span> and <span class="monospaced">SetEnv</span> directives of <a href="http://httpd.apache.org/docs/2.4/mod/mod_env.html">mod_env</a>. This is supported starting from Phusion Passenger 4.0.
</p>
</li>
<li>
<p>
When running Nginx, use the <a href="#passenger_set_cgi_param">passenger_set_cgi_param</a> directive.
</p>
</li>
<li>
<p>
Through your <span class="monospaced">bashrc</span>. Starting from version 4.0, Phusion Passenger 4.0 spawns applications through bash and inherit all bash environment variables. Phusion Passenger Standalone tends to be started from the shell and thus inherits all environment variables set by the shell.
</p>
</li>
<li>
<p>
Through Apache and Nginx, as described earlier in this chapter. Any environment variables that you set on Apache and Nginx itself are inherited by Phusion Passenger, and thus by Phusion Passenger-served apps as well.
</p>
</li>
<li>
<p>
Through the application itself. Most programming languages provide APIs for setting environment variables. For example in Ruby you can write:
</p>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>ENV<span style="color: #990000">[</span><span style="color: #FF0000">'FOO'</span><span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">'bar'</span></tt></pre>
</div>
</div>
<div class="paragraph"><p>In Python you can write:</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000080">import</span></span> os
os<span style="color: #990000">.</span>environ<span style="color: #990000">[</span><span style="color: #FF0000">'FOO'</span><span style="color: #990000">]</span> <span style="color: #990000">=</span> <span style="color: #FF0000">'bar'</span></tt></pre>
</div>
</div>
</li>
</ul></div>
</div>
</div>
<div class="sect2">
<a href="javascript:void(0)" class="comments empty" title="Add a comment"><span class="count"></span></a><span class="anchor_helper" id="env_vars_and_sudo"></span><h3 data-comment-topic="environment-variables-and-sudo-1odzcpz" data-anchor="env_vars_and_sudo">16.4. Environment variables and sudo</h3>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note">
</td>
<td class="content">RVM users should always use the <span class="monospaced">rvmsudo</span> command instead of <span class="monospaced">sudo</span>. However all information in this section apply to <span class="monospaced">rvmsudo</span> as well.</td>
</tr></table>
</div>
<div class="paragraph"><p>The <span class="monospaced">sudo</span> command resets all environment variables before running the specified command, for security reasons. So if you set environment variables before running <span class="monospaced">sudo passenger-install-xxx-module</span>, <span class="monospaced">sudo passenger-status</span> or any other commands, then the environment variables are not correctly passed to the command. You can solve this by running sudo with <span class="monospaced">-E</span> (preserve environment variables):</p></div>
<div class="listingblock">
<div class="content">
<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>user@localhost bash$ <span style="font-weight: bold"><span style="color: #0000FF">export</span></span> <span style="color: #009900">APXS2</span><span style="color: #990000">=</span>/usr/sbin/apxs<span style="color: #993399">2</span>
user@localhost bash$ sudo -E passenger-install-apache<span style="color: #993399">2</span>-module</tt></pre>
</div>
</div>
<div class="paragraph"><p>Alternatively, you can obtain a root prompt with sudo first, and <strong>then</strong> set the environment variables, before running any further commands:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>user@localhost bash$ sudo -s
Password: ...
root@localhost bash# export APXS2=/usr/sbin/apxs2
root@localhost bash# passenger-install-apache2-module</pre>
</div>
</div>
<div class="paragraph"><p>Note that for security reasons, <span class="monospaced">sudo</span> <strong>always resets the <span class="monospaced">PATH</span> environment variable</strong>, even if you pass <span class="monospaced">-E</span>! You can get around this problem by obtaining a root prompt first, and then set the environment variables:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>user@localhost bash$ sudo -s
Password: ...
root@localhost bash# export PATH=$PATH:/opt/myruby/bin
root@localhost bash# passenger-install-apache2-module</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
</div>
<script>/*!
* jQuery JavaScript Library v1.7.2
* http://jquery.com/
*
* Copyright 2011, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
* http://sizzlejs.com/
* Copyright 2011, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Fri Jul 5 14:07:58 UTC 2013
*/
(function( window, undefined ) {
// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
navigator = window.navigator,
location = window.location;
var jQuery = (function() {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
// A central reference to the root jQuery(document)
rootjQuery,
// A simple way to check for HTML strings or ID strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
// Check if a string has a non-whitespace character in it
rnotwhite = /\S/,
// Used for trimming whitespace
trimLeft = /^\s+/,
trimRight = /\s+$/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
// JSON RegExp
rvalidchars = /^[\],:{}\s]*$/,
rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
// Useragent RegExp
rwebkit = /(webkit)[ \/]([\w.]+)/,
ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
rmsie = /(msie) ([\w.]+)/,
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
// Matches dashed string for camelizing
rdashAlpha = /-([a-z]|[0-9])/ig,
rmsPrefix = /^-ms-/,
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
return ( letter + "" ).toUpperCase();
},
// Keep a UserAgent string for use with jQuery.browser
userAgent = navigator.userAgent,
// For matching the engine and version of the browser
browserMatch,
// The deferred used on DOM ready
readyList,
// The ready event handler
DOMContentLoaded,
// Save a reference to some core methods
toString = Object.prototype.toString,
hasOwn = Object.prototype.hasOwnProperty,
push = Array.prototype.push,
slice = Array.prototype.slice,
trim = String.prototype.trim,
indexOf = Array.prototype.indexOf,
// [[Class]] -> type pairs
class2type = {};
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function( selector, context, rootjQuery ) {
var match, elem, ret, doc;
// Handle $(""), $(null), or $(undefined)
if ( !selector ) {
return this;
}
// Handle $(DOMElement)
if ( selector.nodeType ) {
this.context = this[0] = selector;
this.length = 1;
return this;
}
// The body element only exists once, optimize finding it
if ( selector === "body" && !context && document.body ) {
this.context = document;
this[0] = document.body;
this.selector = selector;
this.length = 1;
return this;
}
// Handle HTML strings
if ( typeof selector === "string" ) {
// Are we dealing with HTML string or an ID?
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];
} else {
match = quickExpr.exec( selector );
}
// Verify a match, and that no context was specified for #id
if ( match && (match[1] || !context) ) {
// HANDLE: $(html) -> $(array)
if ( match[1] ) {
context = context instanceof jQuery ? context[0] : context;
doc = ( context ? context.ownerDocument || context : document );
// If a single string is passed in and it's a single tag
// just do a createElement and skip the rest
ret = rsingleTag.exec( selector );
if ( ret ) {
if ( jQuery.isPlainObject( context ) ) {
selector = [ document.createElement( ret[1] ) ];
jQuery.fn.attr.call( selector, context, true );
} else {
selector = [ doc.createElement( ret[1] ) ];
}
} else {
ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
selector = ( ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment ).childNodes;
}
return jQuery.merge( this, selector );
// HANDLE: $("#id")
} else {
elem = document.getElementById( match[2] );
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document #6963
if ( elem && elem.parentNode ) {
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id !== match[2] ) {
return rootjQuery.find( selector );
}
// Otherwise, we inject the element directly into the jQuery object
this.length = 1;
this[0] = elem;
}
this.context = document;
this.selector = selector;
return this;
}
// HANDLE: $(expr, $(...))
} else if ( !context || context.jquery ) {
return ( context || rootjQuery ).find( selector );
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
return this.constructor( context ).find( selector );
}
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
if ( selector.selector !== undefined ) {
this.selector = selector.selector;
this.context = selector.context;
}
return jQuery.makeArray( selector, this );
},
// Start with an empty selector
selector: "",
// The current version of jQuery being used
jquery: "1.7.2",
// The default length of a jQuery object is 0
length: 0,
// The number of elements contained in the matched element set
size: function() {
return this.length;
},
toArray: function() {
return slice.call( this, 0 );
},
// Get the Nth element in the matched element set OR
// Get the whole matched element set as a clean array
get: function( num ) {
return num == null ?
// Return a 'clean' array
this.toArray() :
// Return just the object
( num < 0 ? this[ this.length + num ] : this[ num ] );
},
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems, name, selector ) {
// Build a new jQuery matched element set
var ret = this.constructor();
if ( jQuery.isArray( elems ) ) {
push.apply( ret, elems );
} else {
jQuery.merge( ret, elems );
}
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;
if ( name === "find" ) {
ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
} else if ( name ) {
ret.selector = this.selector + "." + name + "(" + selector + ")";
}
// Return the newly-formed element set
return ret;
},
// Execute a callback for every element in the matched set.
// (You can seed the arguments with an array of args, but this is
// only used internally.)
each: function( callback, args ) {
return jQuery.each( this, callback, args );
},
ready: function( fn ) {
// Attach the listeners
jQuery.bindReady();
// Add the callback
readyList.add( fn );
return this;
},
eq: function( i ) {
i = +i;
return i === -1 ?
this.slice( i ) :
this.slice( i, i + 1 );
},
first: function() {
return this.eq( 0 );
},
last: function() {
return this.eq( -1 );
},
slice: function() {
return this.pushStack( slice.apply( this, arguments ),
"slice", slice.call(arguments).join(",") );
},
map: function( callback ) {
return this.pushStack( jQuery.map(this, function( elem, i ) {
return callback.call( elem, i, elem );
}));
},
end: function() {
return this.prevObject || this.constructor(null);
},
// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: push,
sort: [].sort,
splice: [].splice
};
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
jQuery.extend = jQuery.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
target = {};
}
// extend jQuery itself if only one argument is passed
if ( length === i ) {
target = this;
--i;
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) != null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && jQuery.isArray(src) ? src : [];
} else {
clone = src && jQuery.isPlainObject(src) ? src : {};
}
// Never move original objects, clone them
target[ name ] = jQuery.extend( deep, clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
};
jQuery.extend({
noConflict: function( deep ) {
if ( window.$ === jQuery ) {
window.$ = _$;
}
if ( deep && window.jQuery === jQuery ) {
window.jQuery = _jQuery;
}
return jQuery;
},
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
// A counter to track how many items to wait for before
// the ready event fires. See #6781
readyWait: 1,
// Hold (or release) the ready event
holdReady: function( hold ) {
if ( hold ) {
jQuery.readyWait++;
} else {
jQuery.ready( true );
}
},
// Handle when the DOM is ready
ready: function( wait ) {
// Either a released hold or an DOMready/load event and not yet ready
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 1 );
}
// Remember that the DOM is ready
jQuery.isReady = true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !== true && --jQuery.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
readyList.fireWith( document, [ jQuery ] );
// Trigger any bound ready events
if ( jQuery.fn.trigger ) {
jQuery( document ).trigger( "ready" ).off( "ready" );
}
}
},
bindReady: function() {
if ( readyList ) {
return;
}
readyList = jQuery.Callbacks( "once memory" );
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
return setTimeout( jQuery.ready, 1 );
}
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
// A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false );
// If IE event model is used
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent( "onreadystatechange", DOMContentLoaded );
// A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready );
// If IE and not a frame
// continually check to see if the document is ready
var toplevel = false;
try {
toplevel = window.frameElement == null;
} catch(e) {}
if ( document.documentElement.doScroll && toplevel ) {
doScrollCheck();
}
}
},
// See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
isFunction: function( obj ) {
return jQuery.type(obj) === "function";
},
isArray: Array.isArray || function( obj ) {
return jQuery.type(obj) === "array";
},
isWindow: function( obj ) {
return obj != null && obj == obj.window;
},
isNumeric: function( obj ) {
return !isNaN( parseFloat(obj) ) && isFinite( obj );
},
type: function( obj ) {
return obj == null ?
String( obj ) :
class2type[ toString.call(obj) ] || "object";
},
isPlainObject: function( obj ) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
return false;
}
try {
// Not own constructor property must be Object
if ( obj.constructor &&
!hasOwn.call(obj, "constructor") &&
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
} catch ( e ) {
// IE8,9 Will throw exceptions on certain host objects #9897
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var key;
for ( key in obj ) {}
return key === undefined || hasOwn.call( obj, key );
},
isEmptyObject: function( obj ) {
for ( var name in obj ) {
return false;
}
return true;
},
error: function( msg ) {
throw new Error( msg );
},
parseJSON: function( data ) {
if ( typeof data !== "string" || !data ) {
return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );
}
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if ( rvalidchars.test( data.replace( rvalidescape, "@" )
.replace( rvalidtokens, "]" )
.replace( rvalidbraces, "")) ) {
return ( new Function( "return " + data ) )();
}
jQuery.error( "Invalid JSON: " + data );
},
// Cross-browser xml parsing
parseXML: function( data ) {
if ( typeof data !== "string" || !data ) {
return null;
}
var xml, tmp;
try {
if ( window.DOMParser ) { // Standard
tmp = new DOMParser();
xml = tmp.parseFromString( data , "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false";
xml.loadXML( data );
}
} catch( e ) {
xml = undefined;
}
if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
jQuery.error( "Invalid XML: " + data );
}
return xml;
},
noop: function() {},
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
if ( data && rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},
// Convert dashed to camelCase; used by the css and data modules
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
},
// args is for internal usage only
each: function( object, callback, args ) {
var name, i = 0,
length = object.length,
isObj = length === undefined || jQuery.isFunction( object );
if ( args ) {
if ( isObj ) {
for ( name in object ) {
if ( callback.apply( object[ name ], args ) === false ) {
break;
}
}
} else {
for ( ; i < length; ) {
if ( callback.apply( object[ i++ ], args ) === false ) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if ( isObj ) {
for ( name in object ) {
if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
break;
}
}
} else {
for ( ; i < length; ) {
if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
break;
}
}
}
}
return object;
},
// Use native String.trim function wherever possible
trim: trim ?
function( text ) {
return text == null ?
"" :
trim.call( text );
} :
// Otherwise use our own trimming functionality
function( text ) {
return text == null ?
"" :
text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
},
// results is for internal usage only
makeArray: function( array, results ) {
var ret = results || [];
if ( array != null ) {
// The window, strings (and functions) also have 'length'
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
var type = jQuery.type( array );
if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
push.call( ret, array );
} else {
jQuery.merge( ret, array );
}
}
return ret;
},
inArray: function( elem, array, i ) {
var len;
if ( array ) {
if ( indexOf ) {
return indexOf.call( array, elem, i );
}
len = array.length;
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
for ( ; i < len; i++ ) {
// Skip accessing in sparse arrays
if ( i in array && array[ i ] === elem ) {
return i;
}
}
}
return -1;
},
merge: function( first, second ) {
var i = first.length,
j = 0;
if ( typeof second.length === "number" ) {
for ( var l = second.length; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
},
grep: function( elems, callback, inv ) {
var ret = [], retVal;
inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ ) {
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
return ret;
},
// arg is for internal usage only
map: function( elems, callback, arg ) {
var value, key, ret = [],
i = 0,
length = elems.length,
// jquery objects are treated as arrays
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
// Go through the array, translating each of the items to their
if ( isArray ) {
for ( ; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
// Go through every key on the object,
} else {
for ( key in elems ) {
value = callback( elems[ key ], key, arg );
if ( value != null ) {
ret[ ret.length ] = value;
}
}
}
// Flatten any nested arrays
return ret.concat.apply( [], ret );
},
// A global GUID counter for objects
guid: 1,
// Bind a function to a context, optionally partially applying any
// arguments.
proxy: function( fn, context ) {
if ( typeof context === "string" ) {
var tmp = fn[ context ];
context = fn;
fn = tmp;
}
// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( !jQuery.isFunction( fn ) ) {
return undefined;
}
// Simulated bind
var args = slice.call( arguments, 2 ),
proxy = function() {
return fn.apply( context, args.concat( slice.call( arguments ) ) );
};
// Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
return proxy;
},
// Mutifunctional method to get and set values to a collection
// The value/s can optionally be executed if it's a function
access: function( elems, fn, key, value, chainable, emptyGet, pass ) {
var exec,
bulk = key == null,
i = 0,
length = elems.length;
// Sets many values
if ( key && typeof key === "object" ) {
for ( i in key ) {
jQuery.access( elems, fn, i, key[i], 1, emptyGet, value );
}
chainable = 1;
// Sets one value
} else if ( value !== undefined ) {
// Optionally, function values get executed if exec is true
exec = pass === undefined && jQuery.isFunction( value );
if ( bulk ) {
// Bulk operations only iterate when executing function values
if ( exec ) {
exec = fn;
fn = function( elem, key, value ) {
return exec.call( jQuery( elem ), value );
};
// Otherwise they run against the entire set
} else {
fn.call( elems, value );
fn = null;
}
}
if ( fn ) {
for (; i < length; i++ ) {
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
}
}
chainable = 1;
}
return chainable ?
elems :
// Gets
bulk ?
fn.call( elems ) :
length ? fn( elems[0], key ) : emptyGet;
},
now: function() {
return ( new Date() ).getTime();
},
// Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser
uaMatch: function( ua ) {
ua = ua.toLowerCase();
var match = rwebkit.exec( ua ) ||
ropera.exec( ua ) ||
rmsie.exec( ua ) ||
ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
[];
return { browser: match[1] || "", version: match[2] || "0" };
},
sub: function() {
function jQuerySub( selector, context ) {
return new jQuerySub.fn.init( selector, context );
}
jQuery.extend( true, jQuerySub, this );
jQuerySub.superclass = this;
jQuerySub.fn = jQuerySub.prototype = this();
jQuerySub.fn.constructor = jQuerySub;
jQuerySub.sub = this.sub;
jQuerySub.fn.init = function init( selector, context ) {
if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
context = jQuerySub( context );
}
return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
};
jQuerySub.fn.init.prototype = jQuerySub.fn;
var rootjQuerySub = jQuerySub(document);
return jQuerySub;
},
browser: {}
});
// Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
browserMatch = jQuery.uaMatch( userAgent );
if ( browserMatch.browser ) {
jQuery.browser[ browserMatch.browser ] = true;
jQuery.browser.version = browserMatch.version;
}
// Deprecated, use jQuery.browser.webkit instead
if ( jQuery.browser.webkit ) {
jQuery.browser.safari = true;
}
// IE doesn't match non-breaking spaces with \s
if ( rnotwhite.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}
// All jQuery objects should point back to these
rootjQuery = jQuery(document);
// Cleanup functions for the document ready method
if ( document.addEventListener ) {
DOMContentLoaded = function() {
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
jQuery.ready();
};
} else if ( document.attachEvent ) {
DOMContentLoaded = function() {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", DOMContentLoaded );
jQuery.ready();
}
};
}
// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
}
return jQuery;
})();
// String to Object flags format cache
var flagsCache = {};
// Convert String-formatted flags into Object-formatted ones and store in cache
function createFlags( flags ) {
var object = flagsCache[ flags ] = {},
i, length;
flags = flags.split( /\s+/ );
for ( i = 0, length = flags.length; i < length; i++ ) {
object[ flags[i] ] = true;
}
return object;
}
/*
* Create a callback list using the following parameters:
*
* flags: an optional list of space-separated flags that will change how
* the callback list behaves
*
* By default a callback list will act like an event callback list and can be
* "fired" multiple times.
*
* Possible flags:
*
* once: will ensure the callback list can only be fired once (like a Deferred)
*
* memory: will keep track of previous values and will call any callback added
* after the list has been fired right away with the latest "memorized"
* values (like a Deferred)
*
* unique: will ensure a callback can only be added once (no duplicate in the list)
*
* stopOnFalse: interrupt callings when a callback returns false
*
*/
jQuery.Callbacks = function( flags ) {
// Convert flags from String-formatted to Object-formatted
// (we check in cache first)
flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {};
var // Actual callback list
list = [],
// Stack of fire calls for repeatable lists
stack = [],
// Last fire value (for non-forgettable lists)
memory,
// Flag to know if list was already fired
fired,
// Flag to know if list is currently firing
firing,
// First callback to fire (used internally by add and fireWith)
firingStart,
// End of the loop when firing
firingLength,
// Index of currently firing callback (modified by remove if needed)
firingIndex,
// Add one or several callbacks to the list
add = function( args ) {
var i,
length,
elem,
type,
actual;
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type = jQuery.type( elem );
if ( type === "array" ) {
// Inspect recursively
add( elem );
} else if ( type === "function" ) {
// Add if not in unique mode and callback is not in
if ( !flags.unique || !self.has( elem ) ) {
list.push( elem );
}
}
}
},
// Fire callbacks
fire = function( context, args ) {
args = args || [];
memory = !flags.memory || [ context, args ];
fired = true;
firing = true;
firingIndex = firingStart || 0;
firingStart = 0;
firingLength = list.length;
for ( ; list && firingIndex < firingLength; firingIndex++ ) {
if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) {
memory = true; // Mark as halted
break;
}
}
firing = false;
if ( list ) {
if ( !flags.once ) {
if ( stack && stack.length ) {
memory = stack.shift();
self.fireWith( memory[ 0 ], memory[ 1 ] );
}
} else if ( memory === true ) {
self.disable();
} else {
list = [];
}
}
},
// Actual Callbacks object
self = {
// Add a callback or a collection of callbacks to the list
add: function() {
if ( list ) {
var length = list.length;
add( arguments );
// Do we need to add the callbacks to the
// current firing batch?
if ( firing ) {
firingLength = list.length;
// With memory, if we're not firing then
// we should call right away, unless previous
// firing was halted (stopOnFalse)
} else if ( memory && memory !== true ) {
firingStart = length;
fire( memory[ 0 ], memory[ 1 ] );
}
}
return this;
},
// Remove a callback from the list
remove: function() {
if ( list ) {
var args = arguments,
argIndex = 0,
argLength = args.length;
for ( ; argIndex < argLength ; argIndex++ ) {
for ( var i = 0; i < list.length; i++ ) {
if ( args[ argIndex ] === list[ i ] ) {
// Handle firingIndex and firingLength
if ( firing ) {
if ( i <= firingLength ) {
firingLength--;
if ( i <= firingIndex ) {
firingIndex--;
}
}
}
// Remove the element
list.splice( i--, 1 );
// If we have some unicity property then
// we only need to do this once
if ( flags.unique ) {
break;
}
}
}
}
}
return this;
},
// Control if a given callback is in the list
has: function( fn ) {
if ( list ) {
var i = 0,
length = list.length;
for ( ; i < length; i++ ) {
if ( fn === list[ i ] ) {
return true;
}
}
}
return false;
},
// Remove all callbacks from the list
empty: function() {
list = [];
return this;
},
// Have the list do nothing anymore
disable: function() {
list = stack = memory = undefined;
return this;
},
// Is it disabled?
disabled: function() {
return !list;
},
// Lock the list in its current state
lock: function() {
stack = undefined;
if ( !memory || memory === true ) {
self.disable();
}
return this;
},
// Is it locked?
locked: function() {
return !stack;
},
// Call all callbacks with the given context and arguments
fireWith: function( context, args ) {
if ( stack ) {
if ( firing ) {
if ( !flags.once ) {
stack.push( [ context, args ] );
}
} else if ( !( flags.once && memory ) ) {
fire( context, args );
}
}
return this;
},
// Call all the callbacks with the given arguments
fire: function() {
self.fireWith( this, arguments );
return this;
},
// To know if the callbacks have already been called at least once
fired: function() {
return !!fired;
}
};
return self;
};
var // Static reference to slice
sliceDeferred = [].slice;
jQuery.extend({
Deferred: function( func ) {
var doneList = jQuery.Callbacks( "once memory" ),
failList = jQuery.Callbacks( "once memory" ),
progressList = jQuery.Callbacks( "memory" ),
state = "pending",
lists = {
resolve: doneList,
reject: failList,
notify: progressList
},
promise = {
done: doneList.add,
fail: failList.add,
progress: progressList.add,
state: function() {
return state;
},
// Deprecated
isResolved: doneList.fired,
isRejected: failList.fired,
then: function( doneCallbacks, failCallbacks, progressCallbacks ) {
deferred.done( doneCallbacks ).fail( failCallbacks ).progress( progressCallbacks );
return this;
},
always: function() {
deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
return this;
},
pipe: function( fnDone, fnFail, fnProgress ) {
return jQuery.Deferred(function( newDefer ) {
jQuery.each( {
done: [ fnDone, "resolve" ],
fail: [ fnFail, "reject" ],
progress: [ fnProgress, "notify" ]
}, function( handler, data ) {
var fn = data[ 0 ],
action = data[ 1 ],
returned;
if ( jQuery.isFunction( fn ) ) {
deferred[ handler ](function() {
returned = fn.apply( this, arguments );
if ( returned && jQuery.isFunction( returned.promise ) ) {
returned.promise().then( newDefer.resolve, newDefer.reject, newDefer.notify );
} else {
newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
}
});
} else {
deferred[ handler ]( newDefer[ action ] );
}
});
}).promise();
},
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
if ( obj == null ) {
obj = promise;
} else {
for ( var key in promise ) {
obj[ key ] = promise[ key ];
}
}
return obj;
}
},
deferred = promise.promise({}),
key;
for ( key in lists ) {
deferred[ key ] = lists[ key ].fire;
deferred[ key + "With" ] = lists[ key ].fireWith;
}
// Handle state
deferred.done( function() {
state = "resolved";
}, failList.disable, progressList.lock ).fail( function() {
state = "rejected";
}, doneList.disable, progressList.lock );
// Call given func if any
if ( func ) {
func.call( deferred, deferred );
}
// All done!
return deferred;
},
// Deferred helper
when: function( firstParam ) {
var args = sliceDeferred.call( arguments, 0 ),
i = 0,
length = args.length,
pValues = new Array( length ),
count = length,
pCount = length,
deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
firstParam :
jQuery.Deferred(),
promise = deferred.promise();
function resolveFunc( i ) {
return function( value ) {
args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
if ( !( --count ) ) {
deferred.resolveWith( deferred, args );
}
};
}
function progressFunc( i ) {
return function( value ) {
pValues[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
deferred.notifyWith( promise, pValues );
};
}
if ( length > 1 ) {
for ( ; i < length; i++ ) {
if ( args[ i ] && args[ i ].promise && jQuery.isFunction( args[ i ].promise ) ) {
args[ i ].promise().then( resolveFunc(i), deferred.reject, progressFunc(i) );
} else {
--count;
}
}
if ( !count ) {
deferred.resolveWith( deferred, args );
}
} else if ( deferred !== firstParam ) {
deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
}
return promise;
}
});
jQuery.support = (function() {
var support,
all,
a,
select,
opt,
input,
fragment,
tds,
events,
eventName,
i,
isSupported,
div = document.createElement( "div" ),
documentElement = document.documentElement;
// Preliminary tests
div.setAttribute("className", "t");
div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
all = div.getElementsByTagName( "*" );
a = div.getElementsByTagName( "a" )[ 0 ];
// Can't get basic test support
if ( !all || !all.length || !a ) {
return {};
}
// First batch of supports tests
select = document.createElement( "select" );
opt = select.appendChild( document.createElement("option") );
input = div.getElementsByTagName( "input" )[ 0 ];
support = {
// IE strips leading whitespace when .innerHTML is used
leadingWhitespace: ( div.firstChild.nodeType === 3 ),
// Make sure that tbody elements aren't automatically inserted
// IE will insert them into empty tables
tbody: !div.getElementsByTagName("tbody").length,
// Make sure that link elements get serialized correctly by innerHTML
// This requires a wrapper element in IE
htmlSerialize: !!div.getElementsByTagName("link").length,
// Get the style information from getAttribute
// (IE uses .cssText instead)
style: /top/.test( a.getAttribute("style") ),
// Make sure that URLs aren't manipulated
// (IE normalizes it by default)
hrefNormalized: ( a.getAttribute("href") === "/a" ),
// Make sure that element opacity exists
// (IE uses filter instead)
// Use a regex to work around a WebKit issue. See #5145
opacity: /^0.55/.test( a.style.opacity ),
// Verify style float existence
// (IE uses styleFloat instead of cssFloat)
cssFloat: !!a.style.cssFloat,
// Make sure that if no value is specified for a checkbox
// that it defaults to "on".
// (WebKit defaults to "" instead)
checkOn: ( input.value === "on" ),
// Make sure that a selected-by-default option has a working selected property.
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
optSelected: opt.selected,
// Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
getSetAttribute: div.className !== "t",
// Tests for enctype support on a form(#6743)
enctype: !!document.createElement("form").enctype,
// Makes sure cloning an html5 element does not cause problems
// Where outerHTML is undefined, this still works
html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>",
// Will be defined later
submitBubbles: true,
changeBubbles: true,
focusinBubbles: false,
deleteExpando: true,
noCloneEvent: true,
inlineBlockNeedsLayout: false,
shrinkWrapBlocks: false,
reliableMarginRight: true,
pixelMargin: true
};
// jQuery.boxModel DEPRECATED in 1.3, use jQuery.support.boxModel instead
jQuery.boxModel = support.boxModel = (document.compatMode === "CSS1Compat");
// Make sure checked status is properly cloned
input.checked = true;
support.noCloneChecked = input.cloneNode( true ).checked;
// Make sure that the options inside disabled selects aren't marked as disabled
// (WebKit marks them as disabled)
select.disabled = true;
support.optDisabled = !opt.disabled;
// Test to see if it's possible to delete an expando from an element
// Fails in Internet Explorer
try {
delete div.test;
} catch( e ) {
support.deleteExpando = false;
}
if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
div.attachEvent( "onclick", function() {
// Cloning a node shouldn't copy over any
// bound event handlers (IE does this)
support.noCloneEvent = false;
});
div.cloneNode( true ).fireEvent( "onclick" );
}
// Check if a radio maintains its value
// after being appended to the DOM
input = document.createElement("input");
input.value = "t";
input.setAttribute("type", "radio");
support.radioValue = input.value === "t";
input.setAttribute("checked", "checked");
// #11217 - WebKit loses check when the name is after the checked attribute
input.setAttribute( "name", "t" );
div.appendChild( input );
fragment = document.createDocumentFragment();
fragment.appendChild( div.lastChild );
// WebKit doesn't clone checked state correctly in fragments
support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
// Check if a disconnected checkbox will retain its checked
// value of true after appended to the DOM (IE6/7)
support.appendChecked = input.checked;
fragment.removeChild( input );
fragment.appendChild( div );
// Technique from Juriy Zaytsev
// http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
// We only care about the case where non-standard event systems
// are used, namely in IE. Short-circuiting here helps us to
// avoid an eval call (in setAttribute) which can cause CSP
// to go haywire. See: https://developer.mozilla.org/en/Security/CSP
if ( div.attachEvent ) {
for ( i in {
submit: 1,
change: 1,
focusin: 1
}) {
eventName = "on" + i;
isSupported = ( eventName in div );
if ( !isSupported ) {
div.setAttribute( eventName, "return;" );
isSupported = ( typeof div[ eventName ] === "function" );
}
support[ i + "Bubbles" ] = isSupported;
}
}
fragment.removeChild( div );
// Null elements to avoid leaks in IE
fragment = select = opt = div = input = null;
// Run tests that need a body at doc ready
jQuery(function() {
var container, outer, inner, table, td, offsetSupport,
marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight,
paddingMarginBorderVisibility, paddingMarginBorder,
body = document.getElementsByTagName("body")[0];
if ( !body ) {
// Return for frameset docs that don't have a body
return;
}
conMarginTop = 1;
paddingMarginBorder = "padding:0;margin:0;border:";
positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;";
paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;";
style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;";
html = "<div " + style + "display:block;'><div style='" + paddingMarginBorder + "0;display:block;overflow:hidden;'></div></div>" +
"<table " + style + "' cellpadding='0' cellspacing='0'>" +
"<tr><td></td></tr></table>";
container = document.createElement("div");
container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px";
body.insertBefore( container, body.firstChild );
// Construct the test element
div = document.createElement("div");
container.appendChild( div );
// Check if table cells still have offsetWidth/Height when they are set
// to display:none and there are still other visible table cells in a
// table row; if so, offsetWidth/Height are not reliable for use when
// determining if an element has been hidden directly using
// display:none (it is still safe to use offsets if a parent element is
// hidden; don safety goggles and see bug #4512 for more information).
// (only IE 8 fails this test)
div.innerHTML = "<table><tr><td style='" + paddingMarginBorder + "0;display:none'></td><td>t</td></tr></table>";
tds = div.getElementsByTagName( "td" );
isSupported = ( tds[ 0 ].offsetHeight === 0 );
tds[ 0 ].style.display = "";
tds[ 1 ].style.display = "none";
// Check if empty table cells still have offsetWidth/Height
// (IE <= 8 fail this test)
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
// Check if div with explicit width and no margin-right incorrectly
// gets computed margin-right based on width of container. For more
// info see bug #3333
// Fails in WebKit before Feb 2011 nightlies
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
if ( window.getComputedStyle ) {
div.innerHTML = "";
marginDiv = document.createElement( "div" );
marginDiv.style.width = "0";
marginDiv.style.marginRight = "0";
div.style.width = "2px";
div.appendChild( marginDiv );
support.reliableMarginRight =
( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
}
if ( typeof div.style.zoom !== "undefined" ) {
// Check if natively block-level elements act like inline-block
// elements when setting their display to 'inline' and giving
// them layout
// (IE < 8 does this)
div.innerHTML = "";
div.style.width = div.style.padding = "1px";
div.style.border = 0;
div.style.overflow = "hidden";
div.style.display = "inline";
div.style.zoom = 1;
support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 );
// Check if elements with layout shrink-wrap their children
// (IE 6 does this)
div.style.display = "block";
div.style.overflow = "visible";
div.innerHTML = "<div style='width:5px;'></div>";
support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
}
div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility;
div.innerHTML = html;
outer = div.firstChild;
inner = outer.firstChild;
td = outer.nextSibling.firstChild.firstChild;
offsetSupport = {
doesNotAddBorder: ( inner.offsetTop !== 5 ),
doesAddBorderForTableAndCells: ( td.offsetTop === 5 )
};
inner.style.position = "fixed";
inner.style.top = "20px";
// safari subtracts parent border width here which is 5px
offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 );
inner.style.position = inner.style.top = "";
outer.style.overflow = "hidden";
outer.style.position = "relative";
offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 );
offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop );
if ( window.getComputedStyle ) {
div.style.marginTop = "1%";
support.pixelMargin = ( window.getComputedStyle( div, null ) || { marginTop: 0 } ).marginTop !== "1%";
}
if ( typeof container.style.zoom !== "undefined" ) {
container.style.zoom = 1;
}
body.removeChild( container );
marginDiv = div = container = null;
jQuery.extend( support, offsetSupport );
});
return support;
})();
var rbrace = /^(?:\{.*\}|\[.*\])$/,
rmultiDash = /([A-Z])/g;
jQuery.extend({
cache: {},
// Please use with caution
uuid: 0,
// Unique for each copy of jQuery on the page
// Non-digits removed to match rinlinejQuery
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
// The following elements throw uncatchable exceptions if you
// attempt to add expando properties to them.
noData: {
"embed": true,
// Ban all objects except for Flash (which handle expandos)
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
"applet": true
},
hasData: function( elem ) {
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
return !!elem && !isEmptyDataObject( elem );
},
data: function( elem, name, data, pvt /* Internal Use Only */ ) {
if ( !jQuery.acceptData( elem ) ) {
return;
}
var privateCache, thisCache, ret,
internalKey = jQuery.expando,
getByName = typeof name === "string",
// We have to handle DOM nodes and JS objects differently because IE6-7
// can't GC object references properly across the DOM-JS boundary
isNode = elem.nodeType,
// Only DOM nodes need the global jQuery cache; JS object data is
// attached directly to the object so GC can occur automatically
cache = isNode ? jQuery.cache : elem,
// Only defining an ID for JS objects if its cache already exists allows
// the code to shortcut on the same path as a DOM node with no cache
id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey,
isEvents = name === "events";
// Avoid doing any more work than we need to when trying to get data on an
// object that has no data at all
if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) {
return;
}
if ( !id ) {
// Only DOM nodes need a new unique ID for each element since their data
// ends up in the global cache
if ( isNode ) {
elem[ internalKey ] = id = ++jQuery.uuid;
} else {
id = internalKey;
}
}
if ( !cache[ id ] ) {
cache[ id ] = {};
// Avoids exposing jQuery metadata on plain JS objects when the object
// is serialized using JSON.stringify
if ( !isNode ) {
cache[ id ].toJSON = jQuery.noop;
}
}
// An object can be passed to jQuery.data instead of a key/value pair; this gets
// shallow copied over onto the existing cache
if ( typeof name === "object" || typeof name === "function" ) {
if ( pvt ) {
cache[ id ] = jQuery.extend( cache[ id ], name );
} else {
cache[ id ].data = jQuery.extend( cache[ id ].data, name );
}
}
privateCache = thisCache = cache[ id ];
// jQuery data() is stored in a separate object inside the object's internal data
// cache in order to avoid key collisions between internal data and user-defined
// data.
if ( !pvt ) {
if ( !thisCache.data ) {
thisCache.data = {};
}
thisCache = thisCache.data;
}
if ( data !== undefined ) {
thisCache[ jQuery.camelCase( name ) ] = data;
}
// Users should not attempt to inspect the internal events object using jQuery.data,
// it is undocumented and subject to change. But does anyone listen? No.
if ( isEvents && !thisCache[ name ] ) {
return privateCache.events;
}
// Check for both converted-to-camel and non-converted data property names
// If a data property was specified
if ( getByName ) {
// First Try to find as-is property data
ret = thisCache[ name ];
// Test for null|undefined property data
if ( ret == null ) {
// Try to find the camelCased property
ret = thisCache[ jQuery.camelCase( name ) ];
}
} else {
ret = thisCache;
}
return ret;
},
removeData: function( elem, name, pvt /* Internal Use Only */ ) {
if ( !jQuery.acceptData( elem ) ) {
return;
}
var thisCache, i, l,
// Reference to internal data cache key
internalKey = jQuery.expando,
isNode = elem.nodeType,
// See jQuery.data for more information
cache = isNode ? jQuery.cache : elem,
// See jQuery.data for more information
id = isNode ? elem[ internalKey ] : internalKey;
// If there is already no cache entry for this object, there is no
// purpose in continuing
if ( !cache[ id ] ) {
return;
}
if ( name ) {
thisCache = pvt ? cache[ id ] : cache[ id ].data;
if ( thisCache ) {
// Support array or space separated string names for data keys
if ( !jQuery.isArray( name ) ) {
// try the string as a key before any manipulation
if ( name in thisCache ) {
name = [ name ];
} else {
// split the camel cased version by spaces unless a key with the spaces exists
name = jQuery.camelCase( name );
if ( name in thisCache ) {
name = [ name ];
} else {
name = name.split( " " );
}
}
}
for ( i = 0, l = name.length; i < l; i++ ) {
delete thisCache[ name[i] ];
}
// If there is no data left in the cache, we want to continue
// and let the cache object itself get destroyed
if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
return;
}
}
}
// See jQuery.data for more information
if ( !pvt ) {
delete cache[ id ].data;
// Don't destroy the parent cache unless the internal data object
// had been the only thing left in it
if ( !isEmptyDataObject(cache[ id ]) ) {
return;
}
}
// Browsers that fail expando deletion also refuse to delete expandos on
// the window, but it will allow it on all other JS objects; other browsers
// don't care
// Ensure that `cache` is not a window object #10080
if ( jQuery.support.deleteExpando || !cache.setInterval ) {
delete cache[ id ];
} else {
cache[ id ] = null;
}
// We destroyed the cache and need to eliminate the expando on the node to avoid
// false lookups in the cache for entries that no longer exist
if ( isNode ) {
// IE does not allow us to delete expando properties from nodes,
// nor does it have a removeAttribute function on Document nodes;
// we must handle all of these cases
if ( jQuery.support.deleteExpando ) {
delete elem[ internalKey ];
} else if ( elem.removeAttribute ) {
elem.removeAttribute( internalKey );
} else {
elem[ internalKey ] = null;
}
}
},
// For internal use only.
_data: function( elem, name, data ) {
return jQuery.data( elem, name, data, true );
},
// A method for determining if a DOM node can handle the data expando
acceptData: function( elem ) {
if ( elem.nodeName ) {
var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
if ( match ) {
return !(match === true || elem.getAttribute("classid") !== match);
}
}
return true;
}
});
jQuery.fn.extend({
data: function( key, value ) {
var parts, part, attr, name, l,
elem = this[0],
i = 0,
data = null;
// Gets all values
if ( key === undefined ) {
if ( this.length ) {
data = jQuery.data( elem );
if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
attr = elem.attributes;
for ( l = attr.length; i < l; i++ ) {
name = attr[i].name;
if ( name.indexOf( "data-" ) === 0 ) {
name = jQuery.camelCase( name.substring(5) );
dataAttr( elem, name, data[ name ] );
}
}
jQuery._data( elem, "parsedAttrs", true );
}
}
return data;
}
// Sets multiple values
if ( typeof key === "object" ) {
return this.each(function() {
jQuery.data( this, key );
});
}
parts = key.split( ".", 2 );
parts[1] = parts[1] ? "." + parts[1] : "";
part = parts[1] + "!";
return jQuery.access( this, function( value ) {
if ( value === undefined ) {
data = this.triggerHandler( "getData" + part, [ parts[0] ] );
// Try to fetch any internally stored data first
if ( data === undefined && elem ) {
data = jQuery.data( elem, key );
data = dataAttr( elem, key, data );
}
return data === undefined && parts[1] ?
this.data( parts[0] ) :
data;
}
parts[1] = value;
this.each(function() {
var self = jQuery( this );
self.triggerHandler( "setData" + part, parts );
jQuery.data( this, key, value );
self.triggerHandler( "changeData" + part, parts );
});
}, null, value, arguments.length > 1, null, false );
},
removeData: function( key ) {
return this.each(function() {
jQuery.removeData( this, key );
});
}
});
function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
if ( data === undefined && elem.nodeType === 1 ) {
var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
data = elem.getAttribute( name );
if ( typeof data === "string" ) {
try {
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
jQuery.isNumeric( data ) ? +data :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
jQuery.data( elem, key, data );
} else {
data = undefined;
}
}
return data;
}
// checks a cache object for emptiness
function isEmptyDataObject( obj ) {
for ( var name in obj ) {
// if the public data object is empty, the private is still empty
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
continue;
}
if ( name !== "toJSON" ) {
return false;
}
}
return true;
}
function handleQueueMarkDefer( elem, type, src ) {
var deferDataKey = type + "defer",
queueDataKey = type + "queue",
markDataKey = type + "mark",
defer = jQuery._data( elem, deferDataKey );
if ( defer &&
( src === "queue" || !jQuery._data(elem, queueDataKey) ) &&
( src === "mark" || !jQuery._data(elem, markDataKey) ) ) {
// Give room for hard-coded callbacks to fire first
// and eventually mark/queue something else on the element
setTimeout( function() {
if ( !jQuery._data( elem, queueDataKey ) &&
!jQuery._data( elem, markDataKey ) ) {
jQuery.removeData( elem, deferDataKey, true );
defer.fire();
}
}, 0 );
}
}
jQuery.extend({
_mark: function( elem, type ) {
if ( elem ) {
type = ( type || "fx" ) + "mark";
jQuery._data( elem, type, (jQuery._data( elem, type ) || 0) + 1 );
}
},
_unmark: function( force, elem, type ) {
if ( force !== true ) {
type = elem;
elem = force;
force = false;
}
if ( elem ) {
type = type || "fx";
var key = type + "mark",
count = force ? 0 : ( (jQuery._data( elem, key ) || 1) - 1 );
if ( count ) {
jQuery._data( elem, key, count );
} else {
jQuery.removeData( elem, key, true );
handleQueueMarkDefer( elem, type, "mark" );
}
}
},
queue: function( elem, type, data ) {
var q;
if ( elem ) {
type = ( type || "fx" ) + "queue";
q = jQuery._data( elem, type );
// Speed up dequeue by getting out quickly if this is just a lookup
if ( data ) {
if ( !q || jQuery.isArray(data) ) {
q = jQuery._data( elem, type, jQuery.makeArray(data) );
} else {
q.push( data );
}
}
return q || [];
}
},
dequeue: function( elem, type ) {
type = type || "fx";
var queue = jQuery.queue( elem, type ),
fn = queue.shift(),
hooks = {};
// If the fx queue is dequeued, always remove the progress sentinel
if ( fn === "inprogress" ) {
fn = queue.shift();
}
if ( fn ) {
// Add a progress sentinel to prevent the fx queue from being
// automatically dequeued
if ( type === "fx" ) {
queue.unshift( "inprogress" );
}
jQuery._data( elem, type + ".run", hooks );
fn.call( elem, function() {
jQuery.dequeue( elem, type );
}, hooks );
}
if ( !queue.length ) {
jQuery.removeData( elem, type + "queue " + type + ".run", true );
handleQueueMarkDefer( elem, type, "queue" );
}
}
});
jQuery.fn.extend({
queue: function( type, data ) {
var setter = 2;
if ( typeof type !== "string" ) {
data = type;
type = "fx";
setter--;
}
if ( arguments.length < setter ) {
return jQuery.queue( this[0], type );
}
return data === undefined ?
this :
this.each(function() {
var queue = jQuery.queue( this, type, data );
if ( type === "fx" && queue[0] !== "inprogress" ) {
jQuery.dequeue( this, type );
}
});
},
dequeue: function( type ) {
return this.each(function() {
jQuery.dequeue( this, type );
});
},
// Based off of the plugin by Clint Helfers, with permission.
// http://blindsignals.com/index.php/2009/07/jquery-delay/
delay: function( time, type ) {
time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
type = type || "fx";
return this.queue( type, function( next, hooks ) {
var timeout = setTimeout( next, time );
hooks.stop = function() {
clearTimeout( timeout );
};
});
},
clearQueue: function( type ) {
return this.queue( type || "fx", [] );
},
// Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default)
promise: function( type, object ) {
if ( typeof type !== "string" ) {
object = type;
type = undefined;
}
type = type || "fx";
var defer = jQuery.Deferred(),
elements = this,
i = elements.length,
count = 1,
deferDataKey = type + "defer",
queueDataKey = type + "queue",
markDataKey = type + "mark",
tmp;
function resolve() {
if ( !( --count ) ) {
defer.resolveWith( elements, [ elements ] );
}
}
while( i-- ) {
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
jQuery.data( elements[ i ], deferDataKey, jQuery.Callbacks( "once memory" ), true ) )) {
count++;
tmp.add( resolve );
}
}
resolve();
return defer.promise( object );
}
});
var rclass = /[\n\t\r]/g,
rspace = /\s+/,
rreturn = /\r/g,
rtype = /^(?:button|input)$/i,
rfocusable = /^(?:button|input|object|select|textarea)$/i,
rclickable = /^a(?:rea)?$/i,
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
getSetAttribute = jQuery.support.getSetAttribute,
nodeHook, boolHook, fixSpecified;
jQuery.fn.extend({
attr: function( name, value ) {
return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
},
removeAttr: function( name ) {
return this.each(function() {
jQuery.removeAttr( this, name );
});
},
prop: function( name, value ) {
return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
},
removeProp: function( name ) {
name = jQuery.propFix[ name ] || name;
return this.each(function() {
// try/catch handles cases where IE balks (such as removing a property on window)
try {
this[ name ] = undefined;
delete this[ name ];
} catch( e ) {}
});
},
addClass: function( value ) {
var classNames, i, l, elem,
setClass, c, cl;
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
jQuery( this ).addClass( value.call(this, j, this.className) );
});
}
if ( value && typeof value === "string" ) {
classNames = value.split( rspace );
for ( i = 0, l = this.length; i < l; i++ ) {
elem = this[ i ];
if ( elem.nodeType === 1 ) {
if ( !elem.className && classNames.length === 1 ) {
elem.className = value;
} else {
setClass = " " + elem.className + " ";
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
setClass += classNames[ c ] + " ";
}
}
elem.className = jQuery.trim( setClass );
}
}
}
}
return this;
},
removeClass: function( value ) {
var classNames, i, l, elem, className, c, cl;
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
jQuery( this ).removeClass( value.call(this, j, this.className) );
});
}
if ( (value && typeof value === "string") || value === undefined ) {
classNames = ( value || "" ).split( rspace );
for ( i = 0, l = this.length; i < l; i++ ) {
elem = this[ i ];
if ( elem.nodeType === 1 && elem.className ) {
if ( value ) {
className = (" " + elem.className + " ").replace( rclass, " " );
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
className = className.replace(" " + classNames[ c ] + " ", " ");
}
elem.className = jQuery.trim( className );
} else {
elem.className = "";
}
}
}
}
return this;
},
toggleClass: function( value, stateVal ) {
var type = typeof value,
isBool = typeof stateVal === "boolean";
if ( jQuery.isFunction( value ) ) {
return this.each(function( i ) {
jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
});
}
return this.each(function() {
if ( type === "string" ) {
// toggle individual class names
var className,
i = 0,
self = jQuery( this ),
state = stateVal,
classNames = value.split( rspace );
while ( (className = classNames[ i++ ]) ) {
// check each className given, space seperated list
state = isBool ? state : !self.hasClass( className );
self[ state ? "addClass" : "removeClass" ]( className );
}
} else if ( type === "undefined" || type === "boolean" ) {
if ( this.className ) {
// store className if set
jQuery._data( this, "__className__", this.className );
}
// toggle whole className
this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
}
});
},
hasClass: function( selector ) {
var className = " " + selector + " ",
i = 0,
l = this.length;
for ( ; i < l; i++ ) {
if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
return true;
}
}
return false;
},
val: function( value ) {
var hooks, ret, isFunction,
elem = this[0];
if ( !arguments.length ) {
if ( elem ) {
hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
return ret;
}
ret = elem.value;
return typeof ret === "string" ?
// handle most common string cases
ret.replace(rreturn, "") :
// handle cases where value is null/undef or number
ret == null ? "" : ret;
}
return;
}
isFunction = jQuery.isFunction( value );
return this.each(function( i ) {
var self = jQuery(this), val;
if ( this.nodeType !== 1 ) {
return;
}
if ( isFunction ) {
val = value.call( this, i, self.val() );
} else {
val = value;
}
// Treat null/undefined as ""; convert numbers to string
if ( val == null ) {
val = "";
} else if ( typeof val === "number" ) {
val += "";
} else if ( jQuery.isArray( val ) ) {
val = jQuery.map(val, function ( value ) {
return value == null ? "" : value + "";
});
}
hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
// If set returns undefined, fall back to normal setting
if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
this.value = val;
}
});
}
});
jQuery.extend({
valHooks: {
option: {
get: function( elem ) {
// attributes.value is undefined in Blackberry 4.7 but
// uses .value. See #6932
var val = elem.attributes.value;
return !val || val.specified ? elem.value : elem.text;
}
},
select: {
get: function( elem ) {
var value, i, max, option,
index = elem.selectedIndex,
values = [],
options = elem.options,
one = elem.type === "select-one";
// Nothing was selected
if ( index < 0 ) {
return null;
}
// Loop through all the selected options
i = one ? index : 0;
max = one ? index + 1 : options.length;
for ( ; i < max; i++ ) {
option = options[ i ];
// Don't return options that are disabled or in a disabled optgroup
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
(!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
// Get the specific value for the option
value = jQuery( option ).val();
// We don't need an array for one selects
if ( one ) {
return value;
}
// Multi-Selects return an array
values.push( value );
}
}
// Fixes Bug #2551 -- select.val() broken in IE after form.reset()
if ( one && !values.length && options.length ) {
return jQuery( options[ index ] ).val();
}
return values;
},
set: function( elem, value ) {
var values = jQuery.makeArray( value );
jQuery(elem).find("option").each(function() {
this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
});
if ( !values.length ) {
elem.selectedIndex = -1;
}
return values;
}
}
},
attrFn: {
val: true,
css: true,
html: true,
text: true,
data: true,
width: true,
height: true,
offset: true
},
attr: function( elem, name, value, pass ) {
var ret, hooks, notxml,
nType = elem.nodeType;
// don't get/set attributes on text, comment and attribute nodes
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
return;
}
if ( pass && name in jQuery.attrFn ) {
return jQuery( elem )[ name ]( value );
}
// Fallback to prop when attributes are not supported
if ( typeof elem.getAttribute === "undefined" ) {
return jQuery.prop( elem, name, value );
}
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
// All attributes are lowercase
// Grab necessary hook if one is defined
if ( notxml ) {
name = name.toLowerCase();
hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook );
}
if ( value !== undefined ) {
if ( value === null ) {
jQuery.removeAttr( elem, name );
return;
} else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
return ret;
} else {
elem.setAttribute( name, "" + value );
return value;
}
} else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
return ret;
} else {
ret = elem.getAttribute( name );
// Non-existent attributes return null, we normalize to undefined
return ret === null ?
undefined :
ret;
}
},
removeAttr: function( elem, value ) {
var propName, attrNames, name, l, isBool,
i = 0;
if ( value && elem.nodeType === 1 ) {
attrNames = value.toLowerCase().split( rspace );
l = attrNames.length;
for ( ; i < l; i++ ) {
name = attrNames[ i ];
if ( name ) {
propName = jQuery.propFix[ name ] || name;
isBool = rboolean.test( name );
// See #9699 for explanation of this approach (setting first, then removal)
// Do not do this for boolean attributes (see #10870)
if ( !isBool ) {
jQuery.attr( elem, name, "" );
}
elem.removeAttribute( getSetAttribute ? name : propName );
// Set corresponding property to false for boolean attributes
if ( isBool && propName in elem ) {
elem[ propName ] = false;
}
}
}
}
},
attrHooks: {
type: {
set: function( elem, value ) {
// We can't allow the type property to be changed (since it causes problems in IE)
if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
jQuery.error( "type property can't be changed" );
} else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
// Setting the type on a radio button after the value resets the value in IE6-9
// Reset value to it's default in case type is set after value
// This is for element creation
var val = elem.value;
elem.setAttribute( "type", value );
if ( val ) {
elem.value = val;
}
return value;
}
}
},
// Use the value property for back compat
// Use the nodeHook for button elements in IE6/7 (#1954)
value: {
get: function( elem, name ) {
if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
return nodeHook.get( elem, name );
}
return name in elem ?
elem.value :
null;
},
set: function( elem, value, name ) {
if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
return nodeHook.set( elem, value, name );
}
// Does not return so that setAttribute is also used
elem.value = value;
}
}
},
propFix: {
tabindex: "tabIndex",
readonly: "readOnly",
"for": "htmlFor",
"class": "className",
maxlength: "maxLength",
cellspacing: "cellSpacing",
cellpadding: "cellPadding",
rowspan: "rowSpan",
colspan: "colSpan",
usemap: "useMap",
frameborder: "frameBorder",
contenteditable: "contentEditable"
},
prop: function( elem, name, value ) {
var ret, hooks, notxml,
nType = elem.nodeType;
// don't get/set properties on text, comment and attribute nodes
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
return;
}
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
if ( notxml ) {
// Fix name and attach hooks
name = jQuery.propFix[ name ] || name;
hooks = jQuery.propHooks[ name ];
}
if ( value !== undefined ) {
if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
return ret;
} else {
return ( elem[ name ] = value );
}
} else {
if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
return ret;
} else {
return elem[ name ];
}
}
},
propHooks: {
tabIndex: {
get: function( elem ) {
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
var attributeNode = elem.getAttributeNode("tabindex");
return attributeNode && attributeNode.specified ?
parseInt( attributeNode.value, 10 ) :
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
0 :
undefined;
}
}
}
});
// Add the tabIndex propHook to attrHooks for back-compat (different case is intentional)
jQuery.attrHooks.tabindex = jQuery.propHooks.tabIndex;
// Hook for boolean attributes
boolHook = {
get: function( elem, name ) {
// Align boolean attributes with corresponding properties
// Fall back to attribute presence where some booleans are not supported
var attrNode,
property = jQuery.prop( elem, name );
return property === true || typeof property !== "boolean" && ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?
name.toLowerCase() :
undefined;
},
set: function( elem, value, name ) {
var propName;
if ( value === false ) {
// Remove boolean attributes when set to false
jQuery.removeAttr( elem, name );
} else {
// value is true since we know at this point it's type boolean and not false
// Set boolean attributes to the same name and set the DOM property
propName = jQuery.propFix[ name ] || name;
if ( propName in elem ) {
// Only set the IDL specifically if it already exists on the element
elem[ propName ] = true;
}
elem.setAttribute( name, name.toLowerCase() );
}
return name;
}
};
// IE6/7 do not support getting/setting some attributes with get/setAttribute
if ( !getSetAttribute ) {
fixSpecified = {
name: true,
id: true,
coords: true
};
// Use this for any attribute in IE6/7
// This fixes almost every IE6/7 issue
nodeHook = jQuery.valHooks.button = {
get: function( elem, name ) {
var ret;
ret = elem.getAttributeNode( name );
return ret && ( fixSpecified[ name ] ? ret.nodeValue !== "" : ret.specified ) ?
ret.nodeValue :
undefined;
},
set: function( elem, value, name ) {
// Set the existing or create a new attribute node
var ret = elem.getAttributeNode( name );
if ( !ret ) {
ret = document.createAttribute( name );
elem.setAttributeNode( ret );
}
return ( ret.nodeValue = value + "" );
}
};
// Apply the nodeHook to tabindex
jQuery.attrHooks.tabindex.set = nodeHook.set;
// Set width and height to auto instead of 0 on empty string( Bug #8150 )
// This is for removals
jQuery.each([ "width", "height" ], function( i, name ) {
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
set: function( elem, value ) {
if ( value === "" ) {
elem.setAttribute( name, "auto" );
return value;
}
}
});
});
// Set contenteditable to false on removals(#10429)
// Setting to empty string throws an error as an invalid value
jQuery.attrHooks.contenteditable = {
get: nodeHook.get,
set: function( elem, value, name ) {
if ( value === "" ) {
value = "false";
}
nodeHook.set( elem, value, name );
}
};
}
// Some attributes require a special call on IE
if ( !jQuery.support.hrefNormalized ) {
jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
get: function( elem ) {
var ret = elem.getAttribute( name, 2 );
return ret === null ? undefined : ret;
}
});
});
}
if ( !jQuery.support.style ) {
jQuery.attrHooks.style = {
get: function( elem ) {
// Return undefined in the case of empty string
// Normalize to lowercase since IE uppercases css property names
return elem.style.cssText.toLowerCase() || undefined;
},
set: function( elem, value ) {
return ( elem.style.cssText = "" + value );
}
};
}
// Safari mis-reports the default selected property of an option
// Accessing the parent's selectedIndex property fixes it
if ( !jQuery.support.optSelected ) {
jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
get: function( elem ) {
var parent = elem.parentNode;
if ( parent ) {
parent.selectedIndex;
// Make sure that it also works with optgroups, see #5701
if ( parent.parentNode ) {
parent.parentNode.selectedIndex;
}
}
return null;
}
});
}
// IE6/7 call enctype encoding
if ( !jQuery.support.enctype ) {
jQuery.propFix.enctype = "encoding";
}
// Radios and checkboxes getter/setter
if ( !jQuery.support.checkOn ) {
jQuery.each([ "radio", "checkbox" ], function() {
jQuery.valHooks[ this ] = {
get: function( elem ) {
// Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
return elem.getAttribute("value") === null ? "on" : elem.value;
}
};
});
}
jQuery.each([ "radio", "checkbox" ], function() {
jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
set: function( elem, value ) {
if ( jQuery.isArray( value ) ) {
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
}
}
});
});
var rformElems = /^(?:textarea|input|select)$/i,
rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/,
rhoverHack = /(?:^|\s)hover(\.\S+)?\b/,
rkeyEvent = /^key/,
rmouseEvent = /^(?:mouse|contextmenu)|click/,
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
quickParse = function( selector ) {
var quick = rquickIs.exec( selector );
if ( quick ) {
// 0 1 2 3
// [ _, tag, id, class ]
quick[1] = ( quick[1] || "" ).toLowerCase();
quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" );
}
return quick;
},
quickIs = function( elem, m ) {
var attrs = elem.attributes || {};
return (
(!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
(!m[2] || (attrs.id || {}).value === m[2]) &&
(!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
);
},
hoverHack = function( events ) {
return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
};
/*
* Helper functions for managing events -- not part of the public interface.
* Props to Dean Edwards' addEvent library for many of the ideas.
*/
jQuery.event = {
add: function( elem, types, handler, data, selector ) {
var elemData, eventHandle, events,
t, tns, type, namespaces, handleObj,
handleObjIn, quick, handlers, special;
// Don't attach events to noData or text/comment nodes (allow plain objects tho)
if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
return;
}
// Caller can pass in an object of custom data in lieu of the handler
if ( handler.handler ) {
handleObjIn = handler;
handler = handleObjIn.handler;
selector = handleObjIn.selector;
}
// Make sure that the handler has a unique ID, used to find/remove it later
if ( !handler.guid ) {
handler.guid = jQuery.guid++;
}
// Init the element's event structure and main handler, if this is the first
events = elemData.events;
if ( !events ) {
elemData.events = events = {};
}
eventHandle = elemData.handle;
if ( !eventHandle ) {
elemData.handle = eventHandle = function( e ) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
undefined;
};
// Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
eventHandle.elem = elem;
}
// Handle multiple events separated by a space
// jQuery(...).bind("mouseover mouseout", fn);
types = jQuery.trim( hoverHack(types) ).split( " " );
for ( t = 0; t < types.length; t++ ) {
tns = rtypenamespace.exec( types[t] ) || [];
type = tns[1];
namespaces = ( tns[2] || "" ).split( "." ).sort();
// If event changes its type, use the special event handlers for the changed type
special = jQuery.event.special[ type ] || {};
// If selector defined, determine special event api type, otherwise given type
type = ( selector ? special.delegateType : special.bindType ) || type;
// Update special based on newly reset type
special = jQuery.event.special[ type ] || {};
// handleObj is passed to all event handlers
handleObj = jQuery.extend({
type: type,
origType: tns[1],
data: data,
handler: handler,
guid: handler.guid,
selector: selector,
quick: selector && quickParse( selector ),
namespace: namespaces.join(".")
}, handleObjIn );
// Init the event handler queue if we're the first
handlers = events[ type ];
if ( !handlers ) {
handlers = events[ type ] = [];
handlers.delegateCount = 0;
// Only use addEventListener/attachEvent if the special events handler returns false
if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
// Bind the global event handler to the element
if ( elem.addEventListener ) {
elem.addEventListener( type, eventHandle, false );
} else if ( elem.attachEvent ) {
elem.attachEvent( "on" + type, eventHandle );
}
}
}
if ( special.add ) {
special.add.call( elem, handleObj );
if ( !handleObj.handler.guid ) {
handleObj.handler.guid = handler.guid;
}
}
// Add to the element's handler list, delegates in front
if ( selector ) {
handlers.splice( handlers.delegateCount++, 0, handleObj );
} else {
handlers.push( handleObj );
}
// Keep track of which events have ever been used, for event optimization
jQuery.event.global[ type ] = true;
}
// Nullify elem to prevent memory leaks in IE
elem = null;
},
global: {},
// Detach an event or set of events from an element
remove: function( elem, types, handler, selector, mappedTypes ) {
var elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
t, tns, type, origType, namespaces, origCount,
j, events, special, handle, eventType, handleObj;
if ( !elemData || !(events = elemData.events) ) {
return;
}
// Once for each type.namespace in types; type may be omitted
types = jQuery.trim( hoverHack( types || "" ) ).split(" ");
for ( t = 0; t < types.length; t++ ) {
tns = rtypenamespace.exec( types[t] ) || [];
type = origType = tns[1];
namespaces = tns[2];
// Unbind all events (on this namespace, if provided) for the element
if ( !type ) {
for ( type in events ) {
jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
}
continue;
}
special = jQuery.event.special[ type ] || {};
type = ( selector? special.delegateType : special.bindType ) || type;
eventType = events[ type ] || [];
origCount = eventType.length;
namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
// Remove matching events
for ( j = 0; j < eventType.length; j++ ) {
handleObj = eventType[ j ];
if ( ( mappedTypes || origType === handleObj.origType ) &&
( !handler || handler.guid === handleObj.guid ) &&
( !namespaces || namespaces.test( handleObj.namespace ) ) &&
( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
eventType.splice( j--, 1 );
if ( handleObj.selector ) {
eventType.delegateCount--;
}
if ( special.remove ) {
special.remove.call( elem, handleObj );
}
}
}
// Remove generic event handler if we removed something and no more handlers exist
// (avoids potential for endless recursion during removal of special event handlers)
if ( eventType.length === 0 && origCount !== eventType.length ) {
if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
jQuery.removeEvent( elem, type, elemData.handle );
}
delete events[ type ];
}
}
// Remove the expando if it's no longer used
if ( jQuery.isEmptyObject( events ) ) {
handle = elemData.handle;
if ( handle ) {
handle.elem = null;
}
// removeData also checks for emptiness and clears the expando if empty
// so use it instead of delete
jQuery.removeData( elem, [ "events", "handle" ], true );
}
},
// Events that are safe to short-circuit if no handlers are attached.
// Native DOM events should not be added, they may have inline handlers.
customEvent: {
"getData": true,
"setData": true,
"changeData": true
},
trigger: function( event, data, elem, onlyHandlers ) {
// Don't do events on text and comment nodes
if ( elem && (elem.nodeType === 3 || elem.nodeType === 8) ) {
return;
}
// Event object or event type
var type = event.type || event,
namespaces = [],
cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType;
// focus/blur morphs to focusin/out; ensure we're not firing them right now
if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
return;
}
if ( type.indexOf( "!" ) >= 0 ) {
// Exclusive events trigger only for the exact event (no namespaces)
type = type.slice(0, -1);
exclusive = true;
}
if ( type.indexOf( "." ) >= 0 ) {
// Namespaced trigger; create a regexp to match event type in handle()
namespaces = type.split(".");
type = namespaces.shift();
namespaces.sort();
}
if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
// No jQuery handlers for this event type, and it can't have inline handlers
return;
}
// Caller can pass in an Event, Object, or just an event type string
event = typeof event === "object" ?
// jQuery.Event object
event[ jQuery.expando ] ? event :
// Object literal
new jQuery.Event( type, event ) :
// Just the event type (string)
new jQuery.Event( type );
event.type = type;
event.isTrigger = true;
event.exclusive = exclusive;
event.namespace = namespaces.join( "." );
event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
// Handle a global trigger
if ( !elem ) {
// TODO: Stop taunting the data cache; remove global events and always attach to document
cache = jQuery.cache;
for ( i in cache ) {
if ( cache[ i ].events && cache[ i ].events[ type ] ) {
jQuery.event.trigger( event, data, cache[ i ].handle.elem, true );
}
}
return;
}
// Clean up the event in case it is being reused
event.result = undefined;
if ( !event.target ) {
event.target = elem;
}
// Clone any incoming data and prepend the event, creating the handler arg list
data = data != null ? jQuery.makeArray( data ) : [];
data.unshift( event );
// Allow special events to draw outside the lines
special = jQuery.event.special[ type ] || {};
if ( special.trigger && special.trigger.apply( elem, data ) === false ) {
return;
}
// Determine event propagation path in advance, per W3C events spec (#9951)
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
eventPath = [[ elem, special.bindType || type ]];
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
bubbleType = special.delegateType || type;
cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
old = null;
for ( ; cur; cur = cur.parentNode ) {
eventPath.push([ cur, bubbleType ]);
old = cur;
}
// Only add window if we got to document (e.g., not plain obj or detached DOM)
if ( old && old === elem.ownerDocument ) {
eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
}
}
// Fire handlers on the event path
for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) {
cur = eventPath[i][0];
event.type = eventPath[i][1];
handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
if ( handle ) {
handle.apply( cur, data );
}
// Note that this is a bare JS function and not a jQuery handler
handle = ontype && cur[ ontype ];
if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
event.preventDefault();
}
}
event.type = type;
// If nobody prevented the default action, do it now
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
!(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
// Call a native DOM method on the target with the same name name as the event.
// Can't use an .isFunction() check here because IE6/7 fails that test.
// Don't do default actions on window, that's where global variables be (#6170)
// IE<9 dies on focus/blur to hidden element (#1486)
if ( ontype && elem[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) && !jQuery.isWindow( elem ) ) {
// Don't re-trigger an onFOO event when we call its FOO() method
old = elem[ ontype ];
if ( old ) {
elem[ ontype ] = null;
}
// Prevent re-triggering of the same event, since we already bubbled it above
jQuery.event.triggered = type;
elem[ type ]();
jQuery.event.triggered = undefined;
if ( old ) {
elem[ ontype ] = old;
}
}
}
}
return event.result;
},
dispatch: function( event ) {
// Make a writable jQuery.Event from the native event object
event = jQuery.event.fix( event || window.event );
var handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []),
delegateCount = handlers.delegateCount,
args = [].slice.call( arguments, 0 ),
run_all = !event.exclusive && !event.namespace,
special = jQuery.event.special[ event.type ] || {},
handlerQueue = [],
i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related;
// Use the fix-ed jQuery.Event rather than the (read-only) native event
args[0] = event;
event.delegateTarget = this;
// Call the preDispatch hook for the mapped type, and let it bail if desired
if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
return;
}
// Determine handlers that should run if there are delegated events
// Avoid non-left-click bubbling in Firefox (#3861)
if ( delegateCount && !(event.button && event.type === "click") ) {
// Pregenerate a single jQuery object for reuse with .is()
jqcur = jQuery(this);
jqcur.context = this.ownerDocument || this;
for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
// Don't process events on disabled elements (#6911, #8165)
if ( cur.disabled !== true ) {
selMatch = {};
matches = [];
jqcur[0] = cur;
for ( i = 0; i < delegateCount; i++ ) {
handleObj = handlers[ i ];
sel = handleObj.selector;
if ( selMatch[ sel ] === undefined ) {
selMatch[ sel ] = (
handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
);
}
if ( selMatch[ sel ] ) {
matches.push( handleObj );
}
}
if ( matches.length ) {
handlerQueue.push({ elem: cur, matches: matches });
}
}
}
}
// Add the remaining (directly-bound) handlers
if ( handlers.length > delegateCount ) {
handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) });
}
// Run delegates first; they may want to stop propagation beneath us
for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) {
matched = handlerQueue[ i ];
event.currentTarget = matched.elem;
for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) {
handleObj = matched.matches[ j ];
// Triggered event must either 1) be non-exclusive and have no namespace, or
// 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
if ( run_all || (!event.namespace && !handleObj.namespace) || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) {
event.data = handleObj.data;
event.handleObj = handleObj;
ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
.apply( matched.elem, args );
if ( ret !== undefined ) {
event.result = ret;
if ( ret === false ) {
event.preventDefault();
event.stopPropagation();
}
}
}
}
}
// Call the postDispatch hook for the mapped type
if ( special.postDispatch ) {
special.postDispatch.call( this, event );
}
return event.result;
},
// Includes some event props shared by KeyEvent and MouseEvent
// *** attrChange attrName relatedNode srcElement are not normalized, non-W3C, deprecated, will be removed in 1.8 ***
props: "attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
fixHooks: {},
keyHooks: {
props: "char charCode key keyCode".split(" "),
filter: function( event, original ) {
// Add which for key events
if ( event.which == null ) {
event.which = original.charCode != null ? original.charCode : original.keyCode;
}
return event;
}
},
mouseHooks: {
props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
filter: function( event, original ) {
var eventDoc, doc, body,
button = original.button,
fromElement = original.fromElement;
// Calculate pageX/Y if missing and clientX/Y available
if ( event.pageX == null && original.clientX != null ) {
eventDoc = event.target.ownerDocument || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
}
// Add relatedTarget, if necessary
if ( !event.relatedTarget && fromElement ) {
event.relatedTarget = fromElement === event.target ? original.toElement : fromElement;
}
// Add which for click: 1 === left; 2 === middle; 3 === right
// Note: button is not normalized, so don't use it
if ( !event.which && button !== undefined ) {
event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
}
return event;
}
},
fix: function( event ) {
if ( event[ jQuery.expando ] ) {
return event;
}
// Create a writable copy of the event object and normalize some properties
var i, prop,
originalEvent = event,
fixHook = jQuery.event.fixHooks[ event.type ] || {},
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
event = jQuery.Event( originalEvent );
for ( i = copy.length; i; ) {
prop = copy[ --i ];
event[ prop ] = originalEvent[ prop ];
}
// Fix target property, if necessary (#1925, IE 6/7/8 & Safari2)
if ( !event.target ) {
event.target = originalEvent.srcElement || document;
}
// Target should not be a text node (#504, Safari)
if ( event.target.nodeType === 3 ) {
event.target = event.target.parentNode;
}
// For mouse/key events; add metaKey if it's not there (#3368, IE6/7/8)
if ( event.metaKey === undefined ) {
event.metaKey = event.ctrlKey;
}
return fixHook.filter? fixHook.filter( event, originalEvent ) : event;
},
special: {
ready: {
// Make sure the ready event is setup
setup: jQuery.bindReady
},
load: {
// Prevent triggered image.load events from bubbling to window.load
noBubble: true
},
focus: {
delegateType: "focusin"
},
blur: {
delegateType: "focusout"
},
beforeunload: {
setup: function( data, namespaces, eventHandle ) {
// We only want to do this special case on windows
if ( jQuery.isWindow( this ) ) {
this.onbeforeunload = eventHandle;
}
},
teardown: function( namespaces, eventHandle ) {
if ( this.onbeforeunload === eventHandle ) {
this.onbeforeunload = null;
}
}
}
},
simulate: function( type, elem, event, bubble ) {
// Piggyback on a donor event to simulate a different one.
// Fake originalEvent to avoid donor's stopPropagation, but if the
// simulated event prevents default then we do the same on the donor.
var e = jQuery.extend(
new jQuery.Event(),
event,
{ type: type,
isSimulated: true,
originalEvent: {}
}
);
if ( bubble ) {
jQuery.event.trigger( e, null, elem );
} else {
jQuery.event.dispatch.call( elem, e );
}
if ( e.isDefaultPrevented() ) {
event.preventDefault();
}
}
};
// Some plugins are using, but it's undocumented/deprecated and will be removed.
// The 1.7 special event interface should provide all the hooks needed now.
jQuery.event.handle = jQuery.event.dispatch;
jQuery.removeEvent = document.removeEventListener ?
function( elem, type, handle ) {
if ( elem.removeEventListener ) {
elem.removeEventListener( type, handle, false );
}
} :
function( elem, type, handle ) {
if ( elem.detachEvent ) {
elem.detachEvent( "on" + type, handle );
}
};
jQuery.Event = function( src, props ) {
// Allow instantiation without the 'new' keyword
if ( !(this instanceof jQuery.Event) ) {
return new jQuery.Event( src, props );
}
// Event object
if ( src && src.type ) {
this.originalEvent = src;
this.type = src.type;
// Events bubbling up the document may have been marked as prevented
// by a handler lower down the tree; reflect the correct value.
this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false ||
src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse;
// Event type
} else {
this.type = src;
}
// Put explicitly provided properties onto the event object
if ( props ) {
jQuery.extend( this, props );
}
// Create a timestamp if incoming event doesn't have one
this.timeStamp = src && src.timeStamp || jQuery.now();
// Mark it as fixed
this[ jQuery.expando ] = true;
};
function returnFalse() {
return false;
}
function returnTrue() {
return true;
}
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
jQuery.Event.prototype = {
preventDefault: function() {
this.isDefaultPrevented = returnTrue;
var e = this.originalEvent;
if ( !e ) {
return;
}
// if preventDefault exists run it on the original event
if ( e.preventDefault ) {
e.preventDefault();
// otherwise set the returnValue property of the original event to false (IE)
} else {
e.returnValue = false;
}
},
stopPropagation: function() {
this.isPropagationStopped = returnTrue;
var e = this.originalEvent;
if ( !e ) {
return;
}
// if stopPropagation exists run it on the original event
if ( e.stopPropagation ) {
e.stopPropagation();
}
// otherwise set the cancelBubble property of the original event to true (IE)
e.cancelBubble = true;
},
stopImmediatePropagation: function() {
this.isImmediatePropagationStopped = returnTrue;
this.stopPropagation();
},
isDefaultPrevented: returnFalse,
isPropagationStopped: returnFalse,
isImmediatePropagationStopped: returnFalse
};
// Create mouseenter/leave events using mouseover/out and event-time checks
jQuery.each({
mouseenter: "mouseover",
mouseleave: "mouseout"
}, function( orig, fix ) {
jQuery.event.special[ orig ] = {
delegateType: fix,
bindType: fix,
handle: function( event ) {
var target = this,
related = event.relatedTarget,
handleObj = event.handleObj,
selector = handleObj.selector,
ret;
// For mousenter/leave call the handler if related is outside the target.
// NB: No relatedTarget if the mouse left/entered the browser window
if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
event.type = handleObj.origType;
ret = handleObj.handler.apply( this, arguments );
event.type = fix;
}
return ret;
}
};
});
// IE submit delegation
if ( !jQuery.support.submitBubbles ) {
jQuery.event.special.submit = {
setup: function() {
// Only need this for delegated form submit events
if ( jQuery.nodeName( this, "form" ) ) {
return false;
}
// Lazy-add a submit handler when a descendant form may potentially be submitted
jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
// Node name check avoids a VML-related crash in IE (#9807)
var elem = e.target,
form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
if ( form && !form._submit_attached ) {
jQuery.event.add( form, "submit._submit", function( event ) {
event._submit_bubble = true;
});
form._submit_attached = true;
}
});
// return undefined since we don't need an event listener
},
postDispatch: function( event ) {
// If form was submitted by the user, bubble the event up the tree
if ( event._submit_bubble ) {
delete event._submit_bubble;
if ( this.parentNode && !event.isTrigger ) {
jQuery.event.simulate( "submit", this.parentNode, event, true );
}
}
},
teardown: function() {
// Only need this for delegated form submit events
if ( jQuery.nodeName( this, "form" ) ) {
return false;
}
// Remove delegated handlers; cleanData eventually reaps submit handlers attached above
jQuery.event.remove( this, "._submit" );
}
};
}
// IE change delegation and checkbox/radio fix
if ( !jQuery.support.changeBubbles ) {
jQuery.event.special.change = {
setup: function() {
if ( rformElems.test( this.nodeName ) ) {
// IE doesn't fire change on a check/radio until blur; trigger it on click
// after a propertychange. Eat the blur-change in special.change.handle.
// This still fires onchange a second time for check/radio after blur.
if ( this.type === "checkbox" || this.type === "radio" ) {
jQuery.event.add( this, "propertychange._change", function( event ) {
if ( event.originalEvent.propertyName === "checked" ) {
this._just_changed = true;
}
});
jQuery.event.add( this, "click._change", function( event ) {
if ( this._just_changed && !event.isTrigger ) {
this._just_changed = false;
jQuery.event.simulate( "change", this, event, true );
}
});
}
return false;
}
// Delegated event; lazy-add a change handler on descendant inputs
jQuery.event.add( this, "beforeactivate._change", function( e ) {
var elem = e.target;
if ( rformElems.test( elem.nodeName ) && !elem._change_attached ) {
jQuery.event.add( elem, "change._change", function( event ) {
if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
jQuery.event.simulate( "change", this.parentNode, event, true );
}
});
elem._change_attached = true;
}
});
},
handle: function( event ) {
var elem = event.target;
// Swallow native change events from checkbox/radio, we already triggered them above
if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) {
return event.handleObj.handler.apply( this, arguments );
}
},
teardown: function() {
jQuery.event.remove( this, "._change" );
return rformElems.test( this.nodeName );
}
};
}
// Create "bubbling" focus and blur events
if ( !jQuery.support.focusinBubbles ) {
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
// Attach a single capturing handler while someone wants focusin/focusout
var attaches = 0,
handler = function( event ) {
jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
};
jQuery.event.special[ fix ] = {
setup: function() {
if ( attaches++ === 0 ) {
document.addEventListener( orig, handler, true );
}
},
teardown: function() {
if ( --attaches === 0 ) {
document.removeEventListener( orig, handler, true );
}
}
};
});
}
jQuery.fn.extend({
on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
var origFn, type;
// Types can be a map of types/handlers
if ( typeof types === "object" ) {
// ( types-Object, selector, data )
if ( typeof selector !== "string" ) { // && selector != null
// ( types-Object, data )
data = data || selector;
selector = undefined;
}
for ( type in types ) {
this.on( type, selector, data, types[ type ], one );
}
return this;
}
if ( data == null && fn == null ) {
// ( types, fn )
fn = selector;
data = selector = undefined;
} else if ( fn == null ) {
if ( typeof selector === "string" ) {
// ( types, selector, fn )
fn = data;
data = undefined;
} else {
// ( types, data, fn )
fn = data;
data = selector;
selector = undefined;
}
}
if ( fn === false ) {
fn = returnFalse;
} else if ( !fn ) {
return this;
}
if ( one === 1 ) {
origFn = fn;
fn = function( event ) {
// Can use an empty set, since event contains the info
jQuery().off( event );
return origFn.apply( this, arguments );
};
// Use same guid so caller can remove using origFn
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
}
return this.each( function() {
jQuery.event.add( this, types, fn, data, selector );
});
},
one: function( types, selector, data, fn ) {
return this.on( types, selector, data, fn, 1 );
},
off: function( types, selector, fn ) {
if ( types && types.preventDefault && types.handleObj ) {
// ( event ) dispatched jQuery.Event
var handleObj = types.handleObj;
jQuery( types.delegateTarget ).off(
handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
handleObj.selector,
handleObj.handler
);
return this;
}
if ( typeof types === "object" ) {
// ( types-object [, selector] )
for ( var type in types ) {
this.off( type, selector, types[ type ] );
}
return this;
}
if ( selector === false || typeof selector === "function" ) {
// ( types [, fn] )
fn = selector;
selector = undefined;
}
if ( fn === false ) {
fn = returnFalse;
}
return this.each(function() {
jQuery.event.remove( this, types, fn, selector );
});
},
bind: function( types, data, fn ) {
return this.on( types, null, data, fn );
},
unbind: function( types, fn ) {
return this.off( types, null, fn );
},
live: function( types, data, fn ) {
jQuery( this.context ).on( types, this.selector, data, fn );
return this;
},
die: function( types, fn ) {
jQuery( this.context ).off( types, this.selector || "**", fn );
return this;
},
delegate: function( selector, types, data, fn ) {
return this.on( types, selector, data, fn );
},
undelegate: function( selector, types, fn ) {
// ( namespace ) or ( selector, types [, fn] )
return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn );
},
trigger: function( type, data ) {
return this.each(function() {
jQuery.event.trigger( type, data, this );
});
},
triggerHandler: function( type, data ) {
if ( this[0] ) {
return jQuery.event.trigger( type, data, this[0], true );
}
},
toggle: function( fn ) {
// Save reference to arguments for access in closure
var args = arguments,
guid = fn.guid || jQuery.guid++,
i = 0,
toggler = function( event ) {
// Figure out which function to execute
var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
// Make sure that clicks stop
event.preventDefault();
// and execute the function
return args[ lastToggle ].apply( this, arguments ) || false;
};
// link all the functions, so any of them can unbind this click handler
toggler.guid = guid;
while ( i < args.length ) {
args[ i++ ].guid = guid;
}
return this.click( toggler );
},
hover: function( fnOver, fnOut ) {
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
}
});
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
if ( fn == null ) {
fn = data;
data = null;
}
return arguments.length > 0 ?
this.on( name, null, data, fn ) :
this.trigger( name );
};
if ( jQuery.attrFn ) {
jQuery.attrFn[ name ] = true;
}
if ( rkeyEvent.test( name ) ) {
jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks;
}
if ( rmouseEvent.test( name ) ) {
jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks;
}
});
/*!
* Sizzle CSS Selector Engine
* Copyright 2011, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
* More information: http://sizzlejs.com/
*/
(function(){
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
expando = "sizcache" + (Math.random() + '').replace('.', ''),
done = 0,
toString = Object.prototype.toString,
hasDuplicate = false,
baseHasDuplicate = true,
rBackslash = /\\/g,
rReturn = /\r\n/g,
rNonWord = /\W/;
// Here we check if the JavaScript engine is using some sort of
// optimization where it does not always call our comparision
// function. If that is the case, discard the hasDuplicate value.
// Thus far that includes Google Chrome.
[0, 0].sort(function() {
baseHasDuplicate = false;
return 0;
});
var Sizzle = function( selector, context, results, seed ) {
results = results || [];
context = context || document;
var origContext = context;
if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
return [];
}
if ( !selector || typeof selector !== "string" ) {
return results;
}
var m, set, checkSet, extra, ret, cur, pop, i,
prune = true,
contextXML = Sizzle.isXML( context ),
parts = [],
soFar = selector;
// Reset the position of the chunker regexp (start from head)
do {
chunker.exec( "" );
m = chunker.exec( soFar );
if ( m ) {
soFar = m[3];
parts.push( m[1] );
if ( m[2] ) {
extra = m[3];
break;
}
}
} while ( m );
if ( parts.length > 1 && origPOS.exec( selector ) ) {
if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
set = posProcess( parts[0] + parts[1], context, seed );
} else {
set = Expr.relative[ parts[0] ] ?
[ context ] :
Sizzle( parts.shift(), context );
while ( parts.length ) {
selector = parts.shift();
if ( Expr.relative[ selector ] ) {
selector += parts.shift();
}
set = posProcess( selector, set, seed );
}
}
} else {
// Take a shortcut and set the context if the root selector is an ID
// (but not if it'll be faster if the inner selector is an ID)
if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
ret = Sizzle.find( parts.shift(), context, contextXML );
context = ret.expr ?
Sizzle.filter( ret.expr, ret.set )[0] :
ret.set[0];
}
if ( context ) {
ret = seed ?
{ expr: parts.pop(), set: makeArray(seed) } :
Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
set = ret.expr ?
Sizzle.filter( ret.expr, ret.set ) :
ret.set;
if ( parts.length > 0 ) {
checkSet = makeArray( set );
} else {
prune = false;
}
while ( parts.length ) {
cur = parts.pop();
pop = cur;
if ( !Expr.relative[ cur ] ) {
cur = "";
} else {
pop = parts.pop();
}
if ( pop == null ) {
pop = context;
}
Expr.relative[ cur ]( checkSet, pop, contextXML );
}
} else {
checkSet = parts = [];
}
}
if ( !checkSet ) {
checkSet = set;
}
if ( !checkSet ) {
Sizzle.error( cur || selector );
}
if ( toString.call(checkSet) === "[object Array]" ) {
if ( !prune ) {
results.push.apply( results, checkSet );
} else if ( context && context.nodeType === 1 ) {
for ( i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
results.push( set[i] );
}
}
} else {
for ( i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
results.push( set[i] );
}
}
}
} else {
makeArray( checkSet, results );
}
if ( extra ) {
Sizzle( extra, origContext, results, seed );
Sizzle.uniqueSort( results );
}
return results;
};
Sizzle.uniqueSort = function( results ) {
if ( sortOrder ) {
hasDuplicate = baseHasDuplicate;
results.sort( sortOrder );
if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[ i - 1 ] ) {
results.splice( i--, 1 );
}
}
}
}
return results;
};
Sizzle.matches = function( expr, set ) {
return Sizzle( expr, null, null, set );
};
Sizzle.matchesSelector = function( node, expr ) {
return Sizzle( expr, null, null, [node] ).length > 0;
};
Sizzle.find = function( expr, context, isXML ) {
var set, i, len, match, type, left;
if ( !expr ) {
return [];
}
for ( i = 0, len = Expr.order.length; i < len; i++ ) {
type = Expr.order[i];
if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
left = match[1];
match.splice( 1, 1 );
if ( left.substr( left.length - 1 ) !== "\\" ) {
match[1] = (match[1] || "").replace( rBackslash, "" );
set = Expr.find[ type ]( match, context, isXML );
if ( set != null ) {
expr = expr.replace( Expr.match[ type ], "" );
break;
}
}
}
}
if ( !set ) {
set = typeof context.getElementsByTagName !== "undefined" ?
context.getElementsByTagName( "*" ) :
[];
}
return { set: set, expr: expr };
};
Sizzle.filter = function( expr, set, inplace, not ) {
var match, anyFound,
type, found, item, filter, left,
i, pass,
old = expr,
result = [],
curLoop = set,
isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
while ( expr && set.length ) {
for ( type in Expr.filter ) {
if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
filter = Expr.filter[ type ];
left = match[1];
anyFound = false;
match.splice(1,1);
if ( left.substr( left.length - 1 ) === "\\" ) {
continue;
}
if ( curLoop === result ) {
result = [];
}
if ( Expr.preFilter[ type ] ) {
match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
if ( !match ) {
anyFound = found = true;
} else if ( match === true ) {
continue;
}
}
if ( match ) {
for ( i = 0; (item = curLoop[i]) != null; i++ ) {
if ( item ) {
found = filter( item, match, i, curLoop );
pass = not ^ found;
if ( inplace && found != null ) {
if ( pass ) {
anyFound = true;
} else {
curLoop[i] = false;
}
} else if ( pass ) {
result.push( item );
anyFound = true;
}
}
}
}
if ( found !== undefined ) {
if ( !inplace ) {
curLoop = result;
}
expr = expr.replace( Expr.match[ type ], "" );
if ( !anyFound ) {
return [];
}
break;
}
}
}
// Improper expression
if ( expr === old ) {
if ( anyFound == null ) {
Sizzle.error( expr );
} else {
break;
}
}
old = expr;
}
return curLoop;
};
Sizzle.error = function( msg ) {
throw new Error( "Syntax error, unrecognized expression: " + msg );
};
/**
* Utility function for retreiving the text value of an array of DOM nodes
* @param {Array|Element} elem
*/
var getText = Sizzle.getText = function( elem ) {
var i, node,
nodeType = elem.nodeType,
ret = "";
if ( nodeType ) {
if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
// Use textContent || innerText for elements
if ( typeof elem.textContent === 'string' ) {
return elem.textContent;
} else if ( typeof elem.innerText === 'string' ) {
// Replace IE's carriage returns
return elem.innerText.replace( rReturn, '' );
} else {
// Traverse it's children
for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
ret += getText( elem );
}
}
} else if ( nodeType === 3 || nodeType === 4 ) {
return elem.nodeValue;
}
} else {
// If no nodeType, this is expected to be an array
for ( i = 0; (node = elem[i]); i++ ) {
// Do not traverse comment nodes
if ( node.nodeType !== 8 ) {
ret += getText( node );
}
}
}
return ret;
};
var Expr = Sizzle.selectors = {
order: [ "ID", "NAME", "TAG" ],
match: {
ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
},
leftMatch: {},
attrMap: {
"class": "className",
"for": "htmlFor"
},
attrHandle: {
href: function( elem ) {
return elem.getAttribute( "href" );
},
type: function( elem ) {
return elem.getAttribute( "type" );
}
},
relative: {
"+": function(checkSet, part){
var isPartStr = typeof part === "string",
isTag = isPartStr && !rNonWord.test( part ),
isPartStrNotTag = isPartStr && !isTag;
if ( isTag ) {
part = part.toLowerCase();
}
for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
if ( (elem = checkSet[i]) ) {
while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
elem || false :
elem === part;
}
}
if ( isPartStrNotTag ) {
Sizzle.filter( part, checkSet, true );
}
},
">": function( checkSet, part ) {
var elem,
isPartStr = typeof part === "string",
i = 0,
l = checkSet.length;
if ( isPartStr && !rNonWord.test( part ) ) {
part = part.toLowerCase();
for ( ; i < l; i++ ) {
elem = checkSet[i];
if ( elem ) {
var parent = elem.parentNode;
checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
}
}
} else {
for ( ; i < l; i++ ) {
elem = checkSet[i];
if ( elem ) {
checkSet[i] = isPartStr ?
elem.parentNode :
elem.parentNode === part;
}
}
if ( isPartStr ) {
Sizzle.filter( part, checkSet, true );
}
}
},
"": function(checkSet, part, isXML){
var nodeCheck,
doneName = done++,
checkFn = dirCheck;
if ( typeof part === "string" && !rNonWord.test( part ) ) {
part = part.toLowerCase();
nodeCheck = part;
checkFn = dirNodeCheck;
}
checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
},
"~": function( checkSet, part, isXML ) {
var nodeCheck,
doneName = done++,
checkFn = dirCheck;
if ( typeof part === "string" && !rNonWord.test( part ) ) {
part = part.toLowerCase();
nodeCheck = part;
checkFn = dirNodeCheck;
}
checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
}
},
find: {
ID: function( match, context, isXML ) {
if ( typeof context.getElementById !== "undefined" && !isXML ) {
var m = context.getElementById(match[1]);
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document #6963
return m && m.parentNode ? [m] : [];
}
},
NAME: function( match, context ) {
if ( typeof context.getElementsByName !== "undefined" ) {
var ret = [],
results = context.getElementsByName( match[1] );
for ( var i = 0, l = results.length; i < l; i++ ) {
if ( results[i].getAttribute("name") === match[1] ) {
ret.push( results[i] );
}
}
return ret.length === 0 ? null : ret;
}
},
TAG: function( match, context ) {
if ( typeof context.getElementsByTagName !== "undefined" ) {
return context.getElementsByTagName( match[1] );
}
}
},
preFilter: {
CLASS: function( match, curLoop, inplace, result, not, isXML ) {
match = " " + match[1].replace( rBackslash, "" ) + " ";
if ( isXML ) {
return match;
}
for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
if ( elem ) {
if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
if ( !inplace ) {
result.push( elem );
}
} else if ( inplace ) {
curLoop[i] = false;
}
}
}
return false;
},
ID: function( match ) {
return match[1].replace( rBackslash, "" );
},
TAG: function( match, curLoop ) {
return match[1].replace( rBackslash, "" ).toLowerCase();
},
CHILD: function( match ) {
if ( match[1] === "nth" ) {
if ( !match[2] ) {
Sizzle.error( match[0] );
}
match[2] = match[2].replace(/^\+|\s*/g, '');
// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
// calculate the numbers (first)n+(last) including if they are negative
match[2] = (test[1] + (test[2] || 1)) - 0;
match[3] = test[3] - 0;
}
else if ( match[2] ) {
Sizzle.error( match[0] );
}
// TODO: Move to normal caching system
match[0] = done++;
return match;
},
ATTR: function( match, curLoop, inplace, result, not, isXML ) {
var name = match[1] = match[1].replace( rBackslash, "" );
if ( !isXML && Expr.attrMap[name] ) {
match[1] = Expr.attrMap[name];
}
// Handle if an un-quoted value was used
match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
if ( match[2] === "~=" ) {
match[4] = " " + match[4] + " ";
}
return match;
},
PSEUDO: function( match, curLoop, inplace, result, not ) {
if ( match[1] === "not" ) {
// If we're dealing with a complex expression, or a simple one
if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
match[3] = Sizzle(match[3], null, null, curLoop);
} else {
var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
if ( !inplace ) {
result.push.apply( result, ret );
}
return false;
}
} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
return true;
}
return match;
},
POS: function( match ) {
match.unshift( true );
return match;
}
},
filters: {
enabled: function( elem ) {
return elem.disabled === false && elem.type !== "hidden";
},
disabled: function( elem ) {
return elem.disabled === true;
},
checked: function( elem ) {
return elem.checked === true;
},
selected: function( elem ) {
// Accessing this property makes selected-by-default
// options in Safari work properly
if ( elem.parentNode ) {
elem.parentNode.selectedIndex;
}
return elem.selected === true;
},
parent: function( elem ) {
return !!elem.firstChild;
},
empty: function( elem ) {
return !elem.firstChild;
},
has: function( elem, i, match ) {
return !!Sizzle( match[3], elem ).length;
},
header: function( elem ) {
return (/h\d/i).test( elem.nodeName );
},
text: function( elem ) {
var attr = elem.getAttribute( "type" ), type = elem.type;
// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
// use getAttribute instead to test this case
return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
},
radio: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
},
checkbox: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
},
file: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
},
password: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
},
submit: function( elem ) {
var name = elem.nodeName.toLowerCase();
return (name === "input" || name === "button") && "submit" === elem.type;
},
image: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
},
reset: function( elem ) {
var name = elem.nodeName.toLowerCase();
return (name === "input" || name === "button") && "reset" === elem.type;
},
button: function( elem ) {
var name = elem.nodeName.toLowerCase();
return name === "input" && "button" === elem.type || name === "button";
},
input: function( elem ) {
return (/input|select|textarea|button/i).test( elem.nodeName );
},
focus: function( elem ) {
return elem === elem.ownerDocument.activeElement;
}
},
setFilters: {
first: function( elem, i ) {
return i === 0;
},
last: function( elem, i, match, array ) {
return i === array.length - 1;
},
even: function( elem, i ) {
return i % 2 === 0;
},
odd: function( elem, i ) {
return i % 2 === 1;
},
lt: function( elem, i, match ) {
return i < match[3] - 0;
},
gt: function( elem, i, match ) {
return i > match[3] - 0;
},
nth: function( elem, i, match ) {
return match[3] - 0 === i;
},
eq: function( elem, i, match ) {
return match[3] - 0 === i;
}
},
filter: {
PSEUDO: function( elem, match, i, array ) {
var name = match[1],
filter = Expr.filters[ name ];
if ( filter ) {
return filter( elem, i, match, array );
} else if ( name === "contains" ) {
return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
} else if ( name === "not" ) {
var not = match[3];
for ( var j = 0, l = not.length; j < l; j++ ) {
if ( not[j] === elem ) {
return false;
}
}
return true;
} else {
Sizzle.error( name );
}
},
CHILD: function( elem, match ) {
var first, last,
doneName, parent, cache,
count, diff,
type = match[1],
node = elem;
switch ( type ) {
case "only":
case "first":
while ( (node = node.previousSibling) ) {
if ( node.nodeType === 1 ) {
return false;
}
}
if ( type === "first" ) {
return true;
}
node = elem;
/* falls through */
case "last":
while ( (node = node.nextSibling) ) {
if ( node.nodeType === 1 ) {
return false;
}
}
return true;
case "nth":
first = match[2];
last = match[3];
if ( first === 1 && last === 0 ) {
return true;
}
doneName = match[0];
parent = elem.parentNode;
if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
count = 0;
for ( node = parent.firstChild; node; node = node.nextSibling ) {
if ( node.nodeType === 1 ) {
node.nodeIndex = ++count;
}
}
parent[ expando ] = doneName;
}
diff = elem.nodeIndex - last;
if ( first === 0 ) {
return diff === 0;
} else {
return ( diff % first === 0 && diff / first >= 0 );
}
}
},
ID: function( elem, match ) {
return elem.nodeType === 1 && elem.getAttribute("id") === match;
},
TAG: function( elem, match ) {
return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
},
CLASS: function( elem, match ) {
return (" " + (elem.className || elem.getAttribute("class")) + " ")
.indexOf( match ) > -1;
},
ATTR: function( elem, match ) {
var name = match[1],
result = Sizzle.attr ?
Sizzle.attr( elem, name ) :
Expr.attrHandle[ name ] ?
Expr.attrHandle[ name ]( elem ) :
elem[ name ] != null ?
elem[ name ] :
elem.getAttribute( name ),
value = result + "",
type = match[2],
check = match[4];
return result == null ?
type === "!=" :
!type && Sizzle.attr ?
result != null :
type === "=" ?
value === check :
type === "*=" ?
value.indexOf(check) >= 0 :
type === "~=" ?
(" " + value + " ").indexOf(check) >= 0 :
!check ?
value && result !== false :
type === "!=" ?
value !== check :
type === "^=" ?
value.indexOf(check) === 0 :
type === "$=" ?
value.substr(value.length - check.length) === check :
type === "|=" ?
value === check || value.substr(0, check.length + 1) === check + "-" :
false;
},
POS: function( elem, match, i, array ) {
var name = match[2],
filter = Expr.setFilters[ name ];
if ( filter ) {
return filter( elem, i, match, array );
}
}
}
};
var origPOS = Expr.match.POS,
fescape = function(all, num){
return "\\" + (num - 0 + 1);
};
for ( var type in Expr.match ) {
Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
}
// Expose origPOS
// "global" as in regardless of relation to brackets/parens
Expr.match.globalPOS = origPOS;
var makeArray = function( array, results ) {
array = Array.prototype.slice.call( array, 0 );
if ( results ) {
results.push.apply( results, array );
return results;
}
return array;
};
// Perform a simple check to determine if the browser is capable of
// converting a NodeList to an array using builtin methods.
// Also verifies that the returned array holds DOM nodes
// (which is not the case in the Blackberry browser)
try {
Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
// Provide a fallback method if it does not work
} catch( e ) {
makeArray = function( array, results ) {
var i = 0,
ret = results || [];
if ( toString.call(array) === "[object Array]" ) {
Array.prototype.push.apply( ret, array );
} else {
if ( typeof array.length === "number" ) {
for ( var l = array.length; i < l; i++ ) {
ret.push( array[i] );
}
} else {
for ( ; array[i]; i++ ) {
ret.push( array[i] );
}
}
}
return ret;
};
}
var sortOrder, siblingCheck;
if ( document.documentElement.compareDocumentPosition ) {
sortOrder = function( a, b ) {
if ( a === b ) {
hasDuplicate = true;
return 0;
}
if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
return a.compareDocumentPosition ? -1 : 1;
}
return a.compareDocumentPosition(b) & 4 ? -1 : 1;
};
} else {
sortOrder = function( a, b ) {
// The nodes are identical, we can exit early
if ( a === b ) {
hasDuplicate = true;
return 0;
// Fallback to using sourceIndex (in IE) if it's available on both nodes
} else if ( a.sourceIndex && b.sourceIndex ) {
return a.sourceIndex - b.sourceIndex;
}
var al, bl,
ap = [],
bp = [],
aup = a.parentNode,
bup = b.parentNode,
cur = aup;
// If the nodes are siblings (or identical) we can do a quick check
if ( aup === bup ) {
return siblingCheck( a, b );
// If no parents were found then the nodes are disconnected
} else if ( !aup ) {
return -1;
} else if ( !bup ) {
return 1;
}
// Otherwise they're somewhere else in the tree so we need
// to build up a full list of the parentNodes for comparison
while ( cur ) {
ap.unshift( cur );
cur = cur.parentNode;
}
cur = bup;
while ( cur ) {
bp.unshift( cur );
cur = cur.parentNode;
}
al = ap.length;
bl = bp.length;
// Start walking down the tree looking for a discrepancy
for ( var i = 0; i < al && i < bl; i++ ) {
if ( ap[i] !== bp[i] ) {
return siblingCheck( ap[i], bp[i] );
}
}
// We ended someplace up the tree so do a sibling check
return i === al ?
siblingCheck( a, bp[i], -1 ) :
siblingCheck( ap[i], b, 1 );
};
siblingCheck = function( a, b, ret ) {
if ( a === b ) {
return ret;
}
var cur = a.nextSibling;
while ( cur ) {
if ( cur === b ) {
return -1;
}
cur = cur.nextSibling;
}
return 1;
};
}
// Check to see if the browser returns elements by name when
// querying by getElementById (and provide a workaround)
(function(){
// We're going to inject a fake input element with a specified name
var form = document.createElement("div"),
id = "script" + (new Date()).getTime(),
root = document.documentElement;
form.innerHTML = "<a name='" + id + "'/>";
// Inject it into the root element, check its status, and remove it quickly
root.insertBefore( form, root.firstChild );
// The workaround has to do additional checks after a getElementById
// Which slows things down for other browsers (hence the branching)
if ( document.getElementById( id ) ) {
Expr.find.ID = function( match, context, isXML ) {
if ( typeof context.getElementById !== "undefined" && !isXML ) {
var m = context.getElementById(match[1]);
return m ?
m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
[m] :
undefined :
[];
}
};
Expr.filter.ID = function( elem, match ) {
var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
return elem.nodeType === 1 && node && node.nodeValue === match;
};
}
root.removeChild( form );
// release memory in IE
root = form = null;
})();
(function(){
// Check to see if the browser returns only elements
// when doing getElementsByTagName("*")
// Create a fake element
var div = document.createElement("div");
div.appendChild( document.createComment("") );
// Make sure no comments are found
if ( div.getElementsByTagName("*").length > 0 ) {
Expr.find.TAG = function( match, context ) {
var results = context.getElementsByTagName( match[1] );
// Filter out possible comments
if ( match[1] === "*" ) {
var tmp = [];
for ( var i = 0; results[i]; i++ ) {
if ( results[i].nodeType === 1 ) {
tmp.push( results[i] );
}
}
results = tmp;
}
return results;
};
}
// Check to see if an attribute returns normalized href attributes
div.innerHTML = "<a href='#'></a>";
if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
div.firstChild.getAttribute("href") !== "#" ) {
Expr.attrHandle.href = function( elem ) {
return elem.getAttribute( "href", 2 );
};
}
// release memory in IE
div = null;
})();
if ( document.querySelectorAll ) {
(function(){
var oldSizzle = Sizzle,
div = document.createElement("div"),
id = "__sizzle__";
div.innerHTML = "<p class='TEST'></p>";
// Safari can't handle uppercase or unicode characters when
// in quirks mode.
if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
return;
}
Sizzle = function( query, context, extra, seed ) {
context = context || document;
// Only use querySelectorAll on non-XML documents
// (ID selectors don't work in non-HTML documents)
if ( !seed && !Sizzle.isXML(context) ) {
// See if we find a selector to speed up
var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
// Speed-up: Sizzle("TAG")
if ( match[1] ) {
return makeArray( context.getElementsByTagName( query ), extra );
// Speed-up: Sizzle(".CLASS")
} else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
return makeArray( context.getElementsByClassName( match[2] ), extra );
}
}
if ( context.nodeType === 9 ) {
// Speed-up: Sizzle("body")
// The body element only exists once, optimize finding it
if ( query === "body" && context.body ) {
return makeArray( [ context.body ], extra );
// Speed-up: Sizzle("#ID")
} else if ( match && match[3] ) {
var elem = context.getElementById( match[3] );
// Check parentNode to catch when Blackberry 4.6 returns
// nodes that are no longer in the document #6963
if ( elem && elem.parentNode ) {
// Handle the case where IE and Opera return items
// by name instead of ID
if ( elem.id === match[3] ) {
return makeArray( [ elem ], extra );
}
} else {
return makeArray( [], extra );
}
}
try {
return makeArray( context.querySelectorAll(query), extra );
} catch(qsaError) {}
// qSA works strangely on Element-rooted queries
// We can work around this by specifying an extra ID on the root
// and working up from there (Thanks to Andrew Dupont for the technique)
// IE 8 doesn't work on object elements
} else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
var oldContext = context,
old = context.getAttribute( "id" ),
nid = old || id,
hasParent = context.parentNode,
relativeHierarchySelector = /^\s*[+~]/.test( query );
if ( !old ) {
context.setAttribute( "id", nid );
} else {
nid = nid.replace( /'/g, "\\$&" );
}
if ( relativeHierarchySelector && hasParent ) {
context = context.parentNode;
}
try {
if ( !relativeHierarchySelector || hasParent ) {
return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
}
} catch(pseudoError) {
} finally {
if ( !old ) {
oldContext.removeAttribute( "id" );
}
}
}
}
return oldSizzle(query, context, extra, seed);
};
for ( var prop in oldSizzle ) {
Sizzle[ prop ] = oldSizzle[ prop ];
}
// release memory in IE
div = null;
})();
}
(function(){
var html = document.documentElement,
matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
if ( matches ) {
// Check to see if it's possible to do matchesSelector
// on a disconnected node (IE 9 fails this)
var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
pseudoWorks = false;
try {
// This should fail with an exception
// Gecko does not error, returns false instead
matches.call( document.documentElement, "[test!='']:sizzle" );
} catch( pseudoError ) {
pseudoWorks = true;
}
Sizzle.matchesSelector = function( node, expr ) {
// Make sure that attribute selectors are quoted
expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
if ( !Sizzle.isXML( node ) ) {
try {
if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
var ret = matches.call( node, expr );
// IE 9's matchesSelector returns false on disconnected nodes
if ( ret || !disconnectedMatch ||
// As well, disconnected nodes are said to be in a document
// fragment in IE 9, so check for that
node.document && node.document.nodeType !== 11 ) {
return ret;
}
}
} catch(e) {}
}
return Sizzle(expr, null, null, [node]).length > 0;
};
}
})();
(function(){
var div = document.createElement("div");
div.innerHTML = "<div class='test e'></div><div class='test'></div>";
// Opera can't find a second classname (in 9.6)
// Also, make sure that getElementsByClassName actually exists
if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
return;
}
// Safari caches class attributes, doesn't catch changes (in 3.2)
div.lastChild.className = "e";
if ( div.getElementsByClassName("e").length === 1 ) {
return;
}
Expr.order.splice(1, 0, "CLASS");
Expr.find.CLASS = function( match, context, isXML ) {
if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
return context.getElementsByClassName(match[1]);
}
};
// release memory in IE
div = null;
})();
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
var match = false;
elem = elem[dir];
while ( elem ) {
if ( elem[ expando ] === doneName ) {
match = checkSet[elem.sizset];
break;
}
if ( elem.nodeType === 1 && !isXML ){
elem[ expando ] = doneName;
elem.sizset = i;
}
if ( elem.nodeName.toLowerCase() === cur ) {
match = elem;
break;
}
elem = elem[dir];
}
checkSet[i] = match;
}
}
}
function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
var match = false;
elem = elem[dir];
while ( elem ) {
if ( elem[ expando ] === doneName ) {
match = checkSet[elem.sizset];
break;
}
if ( elem.nodeType === 1 ) {
if ( !isXML ) {
elem[ expando ] = doneName;
elem.sizset = i;
}
if ( typeof cur !== "string" ) {
if ( elem === cur ) {
match = true;
break;
}
} else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
match = elem;
break;
}
}
elem = elem[dir];
}
checkSet[i] = match;
}
}
}
if ( document.documentElement.contains ) {
Sizzle.contains = function( a, b ) {
return a !== b && (a.contains ? a.contains(b) : true);
};
} else if ( document.documentElement.compareDocumentPosition ) {
Sizzle.contains = function( a, b ) {
return !!(a.compareDocumentPosition(b) & 16);
};
} else {
Sizzle.contains = function() {
return false;
};
}
Sizzle.isXML = function( elem ) {
// documentElement is verified for cases where it doesn't yet exist
// (such as loading iframes in IE - #4833)
var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
return documentElement ? documentElement.nodeName !== "HTML" : false;
};
var posProcess = function( selector, context, seed ) {
var match,
tmpSet = [],
later = "",
root = context.nodeType ? [context] : context;
// Position selectors must be done after the filter
// And so must :not(positional) so we move all PSEUDOs to the end
while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
later += match[0];
selector = selector.replace( Expr.match.PSEUDO, "" );
}
selector = Expr.relative[selector] ? selector + "*" : selector;
for ( var i = 0, l = root.length; i < l; i++ ) {
Sizzle( selector, root[i], tmpSet, seed );
}
return Sizzle.filter( later, tmpSet );
};
// EXPOSE
// Override sizzle attribute retrieval
Sizzle.attr = jQuery.attr;
Sizzle.selectors.attrMap = {};
jQuery.find = Sizzle;
jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.filters;
jQuery.unique = Sizzle.uniqueSort;
jQuery.text = Sizzle.getText;
jQuery.isXMLDoc = Sizzle.isXML;
jQuery.contains = Sizzle.contains;
})();
var runtil = /Until$/,
rparentsprev = /^(?:parents|prevUntil|prevAll)/,
// Note: This RegExp should be improved, or likely pulled from Sizzle
rmultiselector = /,/,
isSimple = /^.[^:#\[\.,]*$/,
slice = Array.prototype.slice,
POS = jQuery.expr.match.globalPOS,
// methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique = {
children: true,
contents: true,
next: true,
prev: true
};
jQuery.fn.extend({
find: function( selector ) {
var self = this,
i, l;
if ( typeof selector !== "string" ) {
return jQuery( selector ).filter(function() {
for ( i = 0, l = self.length; i < l; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
}
});
}
var ret = this.pushStack( "", "find", selector ),
length, n, r;
for ( i = 0, l = this.length; i < l; i++ ) {
length = ret.length;
jQuery.find( selector, this[i], ret );
if ( i > 0 ) {
// Make sure that the results are unique
for ( n = length; n < ret.length; n++ ) {
for ( r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) {
ret.splice(n--, 1);
break;
}
}
}
}
}
return ret;
},
has: function( target ) {
var targets = jQuery( target );
return this.filter(function() {
for ( var i = 0, l = targets.length; i < l; i++ ) {
if ( jQuery.contains( this, targets[i] ) ) {
return true;
}
}
});
},
not: function( selector ) {
return this.pushStack( winnow(this, selector, false), "not", selector);
},
filter: function( selector ) {
return this.pushStack( winnow(this, selector, true), "filter", selector );
},
is: function( selector ) {
return !!selector && (
typeof selector === "string" ?
// If this is a positional selector, check membership in the returned set
// so $("p:first").is("p:last") won't return true for a doc with two "p".
POS.test( selector ) ?
jQuery( selector, this.context ).index( this[0] ) >= 0 :
jQuery.filter( selector, this ).length > 0 :
this.filter( selector ).length > 0 );
},
closest: function( selectors, context ) {
var ret = [], i, l, cur = this[0];
// Array (deprecated as of jQuery 1.7)
if ( jQuery.isArray( selectors ) ) {
var level = 1;
while ( cur && cur.ownerDocument && cur !== context ) {
for ( i = 0; i < selectors.length; i++ ) {
if ( jQuery( cur ).is( selectors[ i ] ) ) {
ret.push({ selector: selectors[ i ], elem: cur, level: level });
}
}
cur = cur.parentNode;
level++;
}
return ret;
}
// String
var pos = POS.test( selectors ) || typeof selectors !== "string" ?
jQuery( selectors, context || this.context ) :
0;
for ( i = 0, l = this.length; i < l; i++ ) {
cur = this[i];
while ( cur ) {
if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) {
ret.push( cur );
break;
} else {
cur = cur.parentNode;
if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
break;
}
}
}
}
ret = ret.length > 1 ? jQuery.unique( ret ) : ret;
return this.pushStack( ret, "closest", selectors );
},
// Determine the position of an element within
// the matched set of elements
index: function( elem ) {
// No argument, return index in parent
if ( !elem ) {
return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1;
}
// index in selector
if ( typeof elem === "string" ) {
return jQuery.inArray( this[0], jQuery( elem ) );
}
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
elem.jquery ? elem[0] : elem, this );
},
add: function( selector, context ) {
var set = typeof selector === "string" ?
jQuery( selector, context ) :
jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
all = jQuery.merge( this.get(), set );
return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
all :
jQuery.unique( all ) );
},
andSelf: function() {
return this.add( this.prevObject );
}
});
// A painfully simple check to see if an element is disconnected
// from a document (should be improved, where feasible).
function isDisconnected( node ) {
return !node || !node.parentNode || node.parentNode.nodeType === 11;
}
jQuery.each({
parent: function( elem ) {
var parent = elem.parentNode;
return parent && parent.nodeType !== 11 ? parent : null;
},
parents: function( elem ) {
return jQuery.dir( elem, "parentNode" );
},
parentsUntil: function( elem, i, until ) {
return jQuery.dir( elem, "parentNode", until );
},
next: function( elem ) {
return jQuery.nth( elem, 2, "nextSibling" );
},
prev: function( elem ) {
return jQuery.nth( elem, 2, "previousSibling" );
},
nextAll: function( elem ) {
return jQuery.dir( elem, "nextSibling" );
},
prevAll: function( elem ) {
return jQuery.dir( elem, "previousSibling" );
},
nextUntil: function( elem, i, until ) {
return jQuery.dir( elem, "nextSibling", until );
},
prevUntil: function( elem, i, until ) {
return jQuery.dir( elem, "previousSibling", until );
},
siblings: function( elem ) {
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
},
children: function( elem ) {
return jQuery.sibling( elem.firstChild );
},
contents: function( elem ) {
return jQuery.nodeName( elem, "iframe" ) ?
elem.contentDocument || elem.contentWindow.document :
jQuery.makeArray( elem.childNodes );
}
}, function( name, fn ) {
jQuery.fn[ name ] = function( until, selector ) {
var ret = jQuery.map( this, fn, until );
if ( !runtil.test( name ) ) {
selector = until;
}
if ( selector && typeof selector === "string" ) {
ret = jQuery.filter( selector, ret );
}
ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;
if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
ret = ret.reverse();
}
return this.pushStack( ret, name, slice.call( arguments ).join(",") );
};
});
jQuery.extend({
filter: function( expr, elems, not ) {
if ( not ) {
expr = ":not(" + expr + ")";
}
return elems.length === 1 ?
jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
jQuery.find.matches(expr, elems);
},
dir: function( elem, dir, until ) {
var matched = [],
cur = elem[ dir ];
while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
if ( cur.nodeType === 1 ) {
matched.push( cur );
}
cur = cur[dir];
}
return matched;
},
nth: function( cur, result, dir, elem ) {
result = result || 1;
var num = 0;
for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType === 1 && ++num === result ) {
break;
}
}
return cur;
},
sibling: function( n, elem ) {
var r = [];
for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
r.push( n );
}
}
return r;
}
});
// Implement the identical functionality for filter and not
function winnow( elements, qualifier, keep ) {
// Can't pass null or undefined to indexOf in Firefox 4
// Set to 0 to skip string check
qualifier = qualifier || 0;
if ( jQuery.isFunction( qualifier ) ) {
return jQuery.grep(elements, function( elem, i ) {
var retVal = !!qualifier.call( elem, i, elem );
return retVal === keep;
});
} else if ( qualifier.nodeType ) {
return jQuery.grep(elements, function( elem, i ) {
return ( elem === qualifier ) === keep;
});
} else if ( typeof qualifier === "string" ) {
var filtered = jQuery.grep(elements, function( elem ) {
return elem.nodeType === 1;
});
if ( isSimple.test( qualifier ) ) {
return jQuery.filter(qualifier, filtered, !keep);
} else {
qualifier = jQuery.filter( qualifier, filtered );
}
}
return jQuery.grep(elements, function( elem, i ) {
return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep;
});
}
function createSafeFragment( document ) {
var list = nodeNames.split( "|" ),
safeFrag = document.createDocumentFragment();
if ( safeFrag.createElement ) {
while ( list.length ) {
safeFrag.createElement(
list.pop()
);
}
}
return safeFrag;
}
var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
"header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rleadingWhitespace = /^\s+/,
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
rtagName = /<([\w:]+)/,
rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/,
rnoInnerhtml = /<(?:script|style)/i,
rnocache = /<(?:script|object|embed|option|style)/i,
rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
// checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rscriptType = /\/(java|ecma)script/i,
rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ],
thead: [ 1, "<table>", "</table>" ],
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
area: [ 1, "<map>", "</map>" ],
_default: [ 0, "", "" ]
},
safeFragment = createSafeFragment( document );
wrapMap.optgroup = wrapMap.option;
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
wrapMap.th = wrapMap.td;
// IE can't serialize <link> and <script> tags normally
if ( !jQuery.support.htmlSerialize ) {
wrapMap._default = [ 1, "div<div>", "</div>" ];
}
jQuery.fn.extend({
text: function( value ) {
return jQuery.access( this, function( value ) {
return value === undefined ?
jQuery.text( this ) :
this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
}, null, value, arguments.length );
},
wrapAll: function( html ) {
if ( jQuery.isFunction( html ) ) {
return this.each(function(i) {
jQuery(this).wrapAll( html.call(this, i) );
});
}
if ( this[0] ) {
// The elements to wrap the target around
var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
if ( this[0].parentNode ) {
wrap.insertBefore( this[0] );
}
wrap.map(function() {
var elem = this;
while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
elem = elem.firstChild;
}
return elem;
}).append( this );
}
return this;
},
wrapInner: function( html ) {
if ( jQuery.isFunction( html ) ) {
return this.each(function(i) {
jQuery(this).wrapInner( html.call(this, i) );
});
}
return this.each(function() {
var self = jQuery( this ),
contents = self.contents();
if ( contents.length ) {
contents.wrapAll( html );
} else {
self.append( html );
}
});
},
wrap: function( html ) {
var isFunction = jQuery.isFunction( html );
return this.each(function(i) {
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
});
},
unwrap: function() {
return this.parent().each(function() {
if ( !jQuery.nodeName( this, "body" ) ) {
jQuery( this ).replaceWith( this.childNodes );
}
}).end();
},
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
},
prepend: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.insertBefore( elem, this.firstChild );
}
});
},
before: function() {
if ( this[0] && this[0].parentNode ) {
return this.domManip(arguments, false, function( elem ) {
this.parentNode.insertBefore( elem, this );
});
} else if ( arguments.length ) {
var set = jQuery.clean( arguments );
set.push.apply( set, this.toArray() );
return this.pushStack( set, "before", arguments );
}
},
after: function() {
if ( this[0] && this[0].parentNode ) {
return this.domManip(arguments, false, function( elem ) {
this.parentNode.insertBefore( elem, this.nextSibling );
});
} else if ( arguments.length ) {
var set = this.pushStack( this, "after", arguments );
set.push.apply( set, jQuery.clean(arguments) );
return set;
}
},
// keepData is for internal use only--do not document
remove: function( selector, keepData ) {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
if ( !keepData && elem.nodeType === 1 ) {
jQuery.cleanData( elem.getElementsByTagName("*") );
jQuery.cleanData( [ elem ] );
}
if ( elem.parentNode ) {
elem.parentNode.removeChild( elem );
}
}
}
return this;
},
empty: function() {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
// Remove element nodes and prevent memory leaks
if ( elem.nodeType === 1 ) {
jQuery.cleanData( elem.getElementsByTagName("*") );
}
// Remove any remaining nodes
while ( elem.firstChild ) {
elem.removeChild( elem.firstChild );
}
}
return this;
},
clone: function( dataAndEvents, deepDataAndEvents ) {
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
return this.map( function () {
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
});
},
html: function( value ) {
return jQuery.access( this, function( value ) {
var elem = this[0] || {},
i = 0,
l = this.length;
if ( value === undefined ) {
return elem.nodeType === 1 ?
elem.innerHTML.replace( rinlinejQuery, "" ) :
null;
}
if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) &&
!wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) {
value = value.replace( rxhtmlTag, "<$1></$2>" );
try {
for (; i < l; i++ ) {
// Remove element nodes and prevent memory leaks
elem = this[i] || {};
if ( elem.nodeType === 1 ) {
jQuery.cleanData( elem.getElementsByTagName( "*" ) );
elem.innerHTML = value;
}
}
elem = 0;
// If using innerHTML throws an exception, use the fallback method
} catch(e) {}
}
if ( elem ) {
this.empty().append( value );
}
}, null, value, arguments.length );
},
replaceWith: function( value ) {
if ( this[0] && this[0].parentNode ) {
// Make sure that the elements are removed from the DOM before they are inserted
// this can help fix replacing a parent with child elements
if ( jQuery.isFunction( value ) ) {
return this.each(function(i) {
var self = jQuery(this), old = self.html();
self.replaceWith( value.call( this, i, old ) );
});
}
if ( typeof value !== "string" ) {
value = jQuery( value ).detach();
}
return this.each(function() {
var next = this.nextSibling,
parent = this.parentNode;
jQuery( this ).remove();
if ( next ) {
jQuery(next).before( value );
} else {
jQuery(parent).append( value );
}
});
} else {
return this.length ?
this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
this;
}
},
detach: function( selector ) {
return this.remove( selector, true );
},
domManip: function( args, table, callback ) {
var results, first, fragment, parent,
value = args[0],
scripts = [];
// We can't cloneNode fragments that contain checked, in WebKit
if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
return this.each(function() {
jQuery(this).domManip( args, table, callback, true );
});
}
if ( jQuery.isFunction(value) ) {
return this.each(function(i) {
var self = jQuery(this);
args[0] = value.call(this, i, table ? self.html() : undefined);
self.domManip( args, table, callback );
});
}
if ( this[0] ) {
parent = value && value.parentNode;
// If we're in a fragment, just use that instead of building a new one
if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
results = { fragment: parent };
} else {
results = jQuery.buildFragment( args, this, scripts );
}
fragment = results.fragment;
if ( fragment.childNodes.length === 1 ) {
first = fragment = fragment.firstChild;
} else {
first = fragment.firstChild;
}
if ( first ) {
table = table && jQuery.nodeName( first, "tr" );
for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
callback.call(
table ?
root(this[i], first) :
this[i],
// Make sure that we do not leak memory by inadvertently discarding
// the original fragment (which might have attached data) instead of
// using it; in addition, use the original fragment object for the last
// item instead of first because it can end up being emptied incorrectly
// in certain situations (Bug #8070).
// Fragments from the fragment cache must always be cloned and never used
// in place.
results.cacheable || ( l > 1 && i < lastIndex ) ?
jQuery.clone( fragment, true, true ) :
fragment
);
}
}
if ( scripts.length ) {
jQuery.each( scripts, function( i, elem ) {
if ( elem.src ) {
jQuery.ajax({
type: "GET",
global: false,
url: elem.src,
async: false,
dataType: "script"
});
} else {
jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
}
if ( elem.parentNode ) {
elem.parentNode.removeChild( elem );
}
});
}
}
return this;
}
});
function root( elem, cur ) {
return jQuery.nodeName(elem, "table") ?
(elem.getElementsByTagName("tbody")[0] ||
elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
elem;
}
function cloneCopyEvent( src, dest ) {
if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
return;
}
var type, i, l,
oldData = jQuery._data( src ),
curData = jQuery._data( dest, oldData ),
events = oldData.events;
if ( events ) {
delete curData.handle;
curData.events = {};
for ( type in events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( dest, type, events[ type ][ i ] );
}
}
}
// make the cloned public data object a copy from the original
if ( curData.data ) {
curData.data = jQuery.extend( {}, curData.data );
}
}
function cloneFixAttributes( src, dest ) {
var nodeName;
// We do not need to do anything for non-Elements
if ( dest.nodeType !== 1 ) {
return;
}
// clearAttributes removes the attributes, which we don't want,
// but also removes the attachEvent events, which we *do* want
if ( dest.clearAttributes ) {
dest.clearAttributes();
}
// mergeAttributes, in contrast, only merges back on the
// original attributes, not the events
if ( dest.mergeAttributes ) {
dest.mergeAttributes( src );
}
nodeName = dest.nodeName.toLowerCase();
// IE6-8 fail to clone children inside object elements that use
// the proprietary classid attribute value (rather than the type
// attribute) to identify the type of content to display
if ( nodeName === "object" ) {
dest.outerHTML = src.outerHTML;
} else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
// IE6-8 fails to persist the checked state of a cloned checkbox
// or radio button. Worse, IE6-7 fail to give the cloned element
// a checked appearance if the defaultChecked value isn't also set
if ( src.checked ) {
dest.defaultChecked = dest.checked = src.checked;
}
// IE6-7 get confused and end up setting the value of a cloned
// checkbox/radio button to an empty string instead of "on"
if ( dest.value !== src.value ) {
dest.value = src.value;
}
// IE6-8 fails to return the selected option to the default selected
// state when cloning options
} else if ( nodeName === "option" ) {
dest.selected = src.defaultSelected;
// IE6-8 fails to set the defaultValue to the correct value when
// cloning other types of input fields
} else if ( nodeName === "input" || nodeName === "textarea" ) {
dest.defaultValue = src.defaultValue;
// IE blanks contents when cloning scripts
} else if ( nodeName === "script" && dest.text !== src.text ) {
dest.text = src.text;
}
// Event data gets referenced instead of copied if the expando
// gets copied too
dest.removeAttribute( jQuery.expando );
// Clear flags for bubbling special change/submit events, they must
// be reattached when the newly cloned events are first activated
dest.removeAttribute( "_submit_attached" );
dest.removeAttribute( "_change_attached" );
}
jQuery.buildFragment = function( args, nodes, scripts ) {
var fragment, cacheable, cacheresults, doc,
first = args[ 0 ];
// nodes may contain either an explicit document object,
// a jQuery collection or context object.
// If nodes[0] contains a valid object to assign to doc
if ( nodes && nodes[0] ) {
doc = nodes[0].ownerDocument || nodes[0];
}
// Ensure that an attr object doesn't incorrectly stand in as a document object
// Chrome and Firefox seem to allow this to occur and will throw exception
// Fixes #8950
if ( !doc.createDocumentFragment ) {
doc = document;
}
// Only cache "small" (1/2 KB) HTML strings that are associated with the main document
// Cloning options loses the selected state, so don't cache them
// IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
// Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
// Lastly, IE6,7,8 will not correctly reuse cached fragments that were created from unknown elems #10501
if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document &&
first.charAt(0) === "<" && !rnocache.test( first ) &&
(jQuery.support.checkClone || !rchecked.test( first )) &&
(jQuery.support.html5Clone || !rnoshimcache.test( first )) ) {
cacheable = true;
cacheresults = jQuery.fragments[ first ];
if ( cacheresults && cacheresults !== 1 ) {
fragment = cacheresults;
}
}
if ( !fragment ) {
fragment = doc.createDocumentFragment();
jQuery.clean( args, doc, fragment, scripts );
}
if ( cacheable ) {
jQuery.fragments[ first ] = cacheresults ? fragment : 1;
}
return { fragment: fragment, cacheable: cacheable };
};
jQuery.fragments = {};
jQuery.each({
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
var ret = [],
insert = jQuery( selector ),
parent = this.length === 1 && this[0].parentNode;
if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
insert[ original ]( this[0] );
return this;
} else {
for ( var i = 0, l = insert.length; i < l; i++ ) {
var elems = ( i > 0 ? this.clone(true) : this ).get();
jQuery( insert[i] )[ original ]( elems );
ret = ret.concat( elems );
}
return this.pushStack( ret, name, insert.selector );
}
};
});
function getAll( elem ) {
if ( typeof elem.getElementsByTagName !== "undefined" ) {
return elem.getElementsByTagName( "*" );
} else if ( typeof elem.querySelectorAll !== "undefined" ) {
return elem.querySelectorAll( "*" );
} else {
return [];
}
}
// Used in clean, fixes the defaultChecked property
function fixDefaultChecked( elem ) {
if ( elem.type === "checkbox" || elem.type === "radio" ) {
elem.defaultChecked = elem.checked;
}
}
// Finds all inputs and passes them to fixDefaultChecked
function findInputs( elem ) {
var nodeName = ( elem.nodeName || "" ).toLowerCase();
if ( nodeName === "input" ) {
fixDefaultChecked( elem );
// Skip scripts, get other children
} else if ( nodeName !== "script" && typeof elem.getElementsByTagName !== "undefined" ) {
jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
}
}
// Derived From: http://www.iecss.com/shimprove/javascript/shimprove.1-0-1.js
function shimCloneNode( elem ) {
var div = document.createElement( "div" );
safeFragment.appendChild( div );
div.innerHTML = elem.outerHTML;
return div.firstChild;
}
jQuery.extend({
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
var srcElements,
destElements,
i,
// IE<=8 does not properly clone detached, unknown element nodes
clone = jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ?
elem.cloneNode( true ) :
shimCloneNode( elem );
if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) &&
(elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
// IE copies events bound via attachEvent when using cloneNode.
// Calling detachEvent on the clone will also remove the events
// from the original. In order to get around this, we use some
// proprietary methods to clear the events. Thanks to MooTools
// guys for this hotness.
cloneFixAttributes( elem, clone );
// Using Sizzle here is crazy slow, so we use getElementsByTagName instead
srcElements = getAll( elem );
destElements = getAll( clone );
// Weird iteration because IE will replace the length property
// with an element if you are cloning the body and one of the
// elements on the page has a name or id of "length"
for ( i = 0; srcElements[i]; ++i ) {
// Ensure that the destination node is not null; Fixes #9587
if ( destElements[i] ) {
cloneFixAttributes( srcElements[i], destElements[i] );
}
}
}
// Copy the events from the original to the clone
if ( dataAndEvents ) {
cloneCopyEvent( elem, clone );
if ( deepDataAndEvents ) {
srcElements = getAll( elem );
destElements = getAll( clone );
for ( i = 0; srcElements[i]; ++i ) {
cloneCopyEvent( srcElements[i], destElements[i] );
}
}
}
srcElements = destElements = null;
// Return the cloned set
return clone;
},
clean: function( elems, context, fragment, scripts ) {
var checkScriptType, script, j,
ret = [];
context = context || document;
// !context.createElement fails in IE with an error but returns typeof 'object'
if ( typeof context.createElement === "undefined" ) {
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
}
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
if ( typeof elem === "number" ) {
elem += "";
}
if ( !elem ) {
continue;
}
// Convert html string into DOM nodes
if ( typeof elem === "string" ) {
if ( !rhtml.test( elem ) ) {
elem = context.createTextNode( elem );
} else {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, "<$1></$2>");
// Trim whitespace, otherwise indexOf won't work as expected
var tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(),
wrap = wrapMap[ tag ] || wrapMap._default,
depth = wrap[0],
div = context.createElement("div"),
safeChildNodes = safeFragment.childNodes,
remove;
// Append wrapper element to unknown element safe doc fragment
if ( context === document ) {
// Use the fragment we've already created for this document
safeFragment.appendChild( div );
} else {
// Use a fragment created with the owner document
createSafeFragment( context ).appendChild( div );
}
// Go to html and back, then peel off extra wrappers
div.innerHTML = wrap[1] + elem + wrap[2];
// Move to the right depth
while ( depth-- ) {
div = div.lastChild;
}
// Remove IE's autoinserted <tbody> from table fragments
if ( !jQuery.support.tbody ) {
// String was a <table>, *may* have spurious <tbody>
var hasBody = rtbody.test(elem),
tbody = tag === "table" && !hasBody ?
div.firstChild && div.firstChild.childNodes :
// String was a bare <thead> or <tfoot>
wrap[1] === "<table>" && !hasBody ?
div.childNodes :
[];
for ( j = tbody.length - 1; j >= 0 ; --j ) {
if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
tbody[ j ].parentNode.removeChild( tbody[ j ] );
}
}
}
// IE completely kills leading whitespace when innerHTML is used
if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
}
elem = div.childNodes;
// Clear elements from DocumentFragment (safeFragment or otherwise)
// to avoid hoarding elements. Fixes #11356
if ( div ) {
div.parentNode.removeChild( div );
// Guard against -1 index exceptions in FF3.6
if ( safeChildNodes.length > 0 ) {
remove = safeChildNodes[ safeChildNodes.length - 1 ];
if ( remove && remove.parentNode ) {
remove.parentNode.removeChild( remove );
}
}
}
}
}
// Resets defaultChecked for any radios and checkboxes
// about to be appended to the DOM in IE 6/7 (#8060)
var len;
if ( !jQuery.support.appendChecked ) {
if ( elem[0] && typeof (len = elem.length) === "number" ) {
for ( j = 0; j < len; j++ ) {
findInputs( elem[j] );
}
} else {
findInputs( elem );
}
}
if ( elem.nodeType ) {
ret.push( elem );
} else {
ret = jQuery.merge( ret, elem );
}
}
if ( fragment ) {
checkScriptType = function( elem ) {
return !elem.type || rscriptType.test( elem.type );
};
for ( i = 0; ret[i]; i++ ) {
script = ret[i];
if ( scripts && jQuery.nodeName( script, "script" ) && (!script.type || rscriptType.test( script.type )) ) {
scripts.push( script.parentNode ? script.parentNode.removeChild( script ) : script );
} else {
if ( script.nodeType === 1 ) {
var jsTags = jQuery.grep( script.getElementsByTagName( "script" ), checkScriptType );
ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
}
fragment.appendChild( script );
}
}
}
return ret;
},
cleanData: function( elems ) {
var data, id,
cache = jQuery.cache,
special = jQuery.event.special,
deleteExpando = jQuery.support.deleteExpando;
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
continue;
}
id = elem[ jQuery.expando ];
if ( id ) {
data = cache[ id ];
if ( data && data.events ) {
for ( var type in data.events ) {
if ( special[ type ] ) {
jQuery.event.remove( elem, type );
// This is a shortcut to avoid jQuery.event.remove's overhead
} else {
jQuery.removeEvent( elem, type, data.handle );
}
}
// Null the DOM reference to avoid IE6/7/8 leak (#7054)
if ( data.handle ) {
data.handle.elem = null;
}
}
if ( deleteExpando ) {
delete elem[ jQuery.expando ];
} else if ( elem.removeAttribute ) {
elem.removeAttribute( jQuery.expando );
}
delete cache[ id ];
}
}
}
});
var ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/,
// fixed for IE9, see #8346
rupper = /([A-Z]|^ms)/g,
rnum = /^[\-+]?(?:\d*\.)?\d+$/i,
rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
rrelNum = /^([\-+])=([\-+.\de]+)/,
rmargin = /^margin/,
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
// order is important!
cssExpand = [ "Top", "Right", "Bottom", "Left" ],
curCSS,
getComputedStyle,
currentStyle;
jQuery.fn.css = function( name, value ) {
return jQuery.access( this, function( elem, name, value ) {
return value !== undefined ?
jQuery.style( elem, name, value ) :
jQuery.css( elem, name );
}, name, value, arguments.length > 1 );
};
jQuery.extend({
// Add in style property hooks for overriding the default
// behavior of getting and setting a style property
cssHooks: {
opacity: {
get: function( elem, computed ) {
if ( computed ) {
// We should always get a number back from opacity
var ret = curCSS( elem, "opacity" );
return ret === "" ? "1" : ret;
} else {
return elem.style.opacity;
}
}
}
},
// Exclude the following css properties to add px
cssNumber: {
"fillOpacity": true,
"fontWeight": true,
"lineHeight": true,
"opacity": true,
"orphans": true,
"widows": true,
"zIndex": true,
"zoom": true
},
// Add in properties whose names you wish to fix before
// setting or getting the value
cssProps: {
// normalize float css property
"float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
},
// Get and set the style property on a DOM Node
style: function( elem, name, value, extra ) {
// Don't set styles on text and comment nodes
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
return;
}
// Make sure that we're working with the right name
var ret, type, origName = jQuery.camelCase( name ),
style = elem.style, hooks = jQuery.cssHooks[ origName ];
name = jQuery.cssProps[ origName ] || origName;
// Check if we're setting a value
if ( value !== undefined ) {
type = typeof value;
// convert relative number strings (+= or -=) to relative numbers. #7345
if ( type === "string" && (ret = rrelNum.exec( value )) ) {
value = ( +( ret[1] + 1) * +ret[2] ) + parseFloat( jQuery.css( elem, name ) );
// Fixes bug #9237
type = "number";
}
// Make sure that NaN and null values aren't set. See: #7116
if ( value == null || type === "number" && isNaN( value ) ) {
return;
}
// If a number was passed in, add 'px' to the (except for certain CSS properties)
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
value += "px";
}
// If a hook was provided, use that value, otherwise just set the specified value
if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
// Wrapped to prevent IE from throwing errors when 'invalid' values are provided
// Fixes bug #5509
try {
style[ name ] = value;
} catch(e) {}
}
} else {
// If a hook was provided get the non-computed value from there
if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
return ret;
}
// Otherwise just get the value from the style object
return style[ name ];
}
},
css: function( elem, name, extra ) {
var ret, hooks;
// Make sure that we're working with the right name
name = jQuery.camelCase( name );
hooks = jQuery.cssHooks[ name ];
name = jQuery.cssProps[ name ] || name;
// cssFloat needs a special treatment
if ( name === "cssFloat" ) {
name = "float";
}
// If a hook was provided get the computed value from there
if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
return ret;
// Otherwise, if a way to get the computed value exists, use that
} else if ( curCSS ) {
return curCSS( elem, name );
}
},
// A method for quickly swapping in/out CSS properties to get correct calculations
swap: function( elem, options, callback ) {
var old = {},
ret, name;
// Remember the old values, and insert the new ones
for ( name in options ) {
old[ name ] = elem.style[ name ];
elem.style[ name ] = options[ name ];
}
ret = callback.call( elem );
// Revert the old values
for ( name in options ) {
elem.style[ name ] = old[ name ];
}
return ret;
}
});
// DEPRECATED in 1.3, Use jQuery.css() instead
jQuery.curCSS = jQuery.css;
if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, name ) {
var ret, defaultView, computedStyle, width,
style = elem.style;
name = name.replace( rupper, "-$1" ).toLowerCase();
if ( (defaultView = elem.ownerDocument.defaultView) &&
(computedStyle = defaultView.getComputedStyle( elem, null )) ) {
ret = computedStyle.getPropertyValue( name );
if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
ret = jQuery.style( elem, name );
}
}
// A tribute to the "awesome hack by Dean Edwards"
// WebKit uses "computed value (percentage if specified)" instead of "used value" for margins
// which is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
if ( !jQuery.support.pixelMargin && computedStyle && rmargin.test( name ) && rnumnonpx.test( ret ) ) {
width = style.width;
style.width = ret;
ret = computedStyle.width;
style.width = width;
}
return ret;
};
}
if ( document.documentElement.currentStyle ) {
currentStyle = function( elem, name ) {
var left, rsLeft, uncomputed,
ret = elem.currentStyle && elem.currentStyle[ name ],
style = elem.style;
// Avoid setting ret to empty string here
// so we don't default to auto
if ( ret == null && style && (uncomputed = style[ name ]) ) {
ret = uncomputed;
}
// From the awesome hack by Dean Edwards
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
// If we're not dealing with a regular pixel number
// but a number that has a weird ending, we need to convert it to pixels
if ( rnumnonpx.test( ret ) ) {
// Remember the original values
left = style.left;
rsLeft = elem.runtimeStyle && elem.runtimeStyle.left;
// Put in the new values to get a computed value out
if ( rsLeft ) {
elem.runtimeStyle.left = elem.currentStyle.left;
}
style.left = name === "fontSize" ? "1em" : ret;
ret = style.pixelLeft + "px";
// Revert the changed values
style.left = left;
if ( rsLeft ) {
elem.runtimeStyle.left = rsLeft;
}
}
return ret === "" ? "auto" : ret;
};
}
curCSS = getComputedStyle || currentStyle;
function getWidthOrHeight( elem, name, extra ) {
// Start with offset property
var val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
i = name === "width" ? 1 : 0,
len = 4;
if ( val > 0 ) {
if ( extra !== "border" ) {
for ( ; i < len; i += 2 ) {
if ( !extra ) {
val -= parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0;
}
if ( extra === "margin" ) {
val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ] ) ) || 0;
} else {
val -= parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0;
}
}
}
return val + "px";
}
// Fall back to computed then uncomputed css if necessary
val = curCSS( elem, name );
if ( val < 0 || val == null ) {
val = elem.style[ name ];
}
// Computed unit is not pixels. Stop here and return.
if ( rnumnonpx.test(val) ) {
return val;
}
// Normalize "", auto, and prepare for extra
val = parseFloat( val ) || 0;
// Add padding, border, margin
if ( extra ) {
for ( ; i < len; i += 2 ) {
val += parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0;
if ( extra !== "padding" ) {
val += parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0;
}
if ( extra === "margin" ) {
val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ]) ) || 0;
}
}
}
return val + "px";
}
jQuery.each([ "height", "width" ], function( i, name ) {
jQuery.cssHooks[ name ] = {
get: function( elem, computed, extra ) {
if ( computed ) {
if ( elem.offsetWidth !== 0 ) {
return getWidthOrHeight( elem, name, extra );
} else {
return jQuery.swap( elem, cssShow, function() {
return getWidthOrHeight( elem, name, extra );
});
}
}
},
set: function( elem, value ) {
return rnum.test( value ) ?
value + "px" :
value;
}
};
});
if ( !jQuery.support.opacity ) {
jQuery.cssHooks.opacity = {
get: function( elem, computed ) {
// IE uses filters for opacity
return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
( parseFloat( RegExp.$1 ) / 100 ) + "" :
computed ? "1" : "";
},
set: function( elem, value ) {
var style = elem.style,
currentStyle = elem.currentStyle,
opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "",
filter = currentStyle && currentStyle.filter || style.filter || "";
// IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level
style.zoom = 1;
// if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652
if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" ) {
// Setting style.filter to null, "" & " " still leave "filter:" in the cssText
// if "filter:" is present at all, clearType is disabled, we want to avoid this
// style.removeAttribute is IE Only, but so apparently is this code path...
style.removeAttribute( "filter" );
// if there there is no filter style applied in a css rule, we are done
if ( currentStyle && !currentStyle.filter ) {
return;
}
}
// otherwise, set new filter values
style.filter = ralpha.test( filter ) ?
filter.replace( ralpha, opacity ) :
filter + " " + opacity;
}
};
}
jQuery(function() {
// This hook cannot be added until DOM ready because the support test
// for it is not run until after DOM ready
if ( !jQuery.support.reliableMarginRight ) {
jQuery.cssHooks.marginRight = {
get: function( elem, computed ) {
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
// Work around by temporarily setting element display to inline-block
return jQuery.swap( elem, { "display": "inline-block" }, function() {
if ( computed ) {
return curCSS( elem, "margin-right" );
} else {
return elem.style.marginRight;
}
});
}
};
}
});
if ( jQuery.expr && jQuery.expr.filters ) {
jQuery.expr.filters.hidden = function( elem ) {
var width = elem.offsetWidth,
height = elem.offsetHeight;
return ( width === 0 && height === 0 ) || (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none");
};
jQuery.expr.filters.visible = function( elem ) {
return !jQuery.expr.filters.hidden( elem );
};
}
// These hooks are used by animate to expand properties
jQuery.each({
margin: "",
padding: "",
border: "Width"
}, function( prefix, suffix ) {
jQuery.cssHooks[ prefix + suffix ] = {
expand: function( value ) {
var i,
// assumes a single number if not a string
parts = typeof value === "string" ? value.split(" ") : [ value ],
expanded = {};
for ( i = 0; i < 4; i++ ) {
expanded[ prefix + cssExpand[ i ] + suffix ] =
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
}
return expanded;
}
};
});
var r20 = /%20/g,
rbracket = /\[\]$/,
rCRLF = /\r?\n/g,
rhash = /#.*$/,
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
// #7653, #8125, #8152: local protocol detection
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
rquery = /\?/,
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rselectTextarea = /^(?:select|textarea)/i,
rspacesAjax = /\s+/,
rts = /([?&])_=[^&]*/,
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
// Keep a copy of the old load method
_load = jQuery.fn.load,
/* Prefilters
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
* 2) These are called:
* - BEFORE asking for a transport
* - AFTER param serialization (s.data is a string if s.processData is true)
* 3) key is the dataType
* 4) the catchall symbol "*" can be used
* 5) execution will start with transport dataType and THEN continue down to "*" if needed
*/
prefilters = {},
/* Transports bindings
* 1) key is the dataType
* 2) the catchall symbol "*" can be used
* 3) selection will start with transport dataType and THEN go to "*" if needed
*/
transports = {},
// Document location
ajaxLocation,
// Document location segments
ajaxLocParts,
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
allTypes = ["*/"] + ["*"];
// #8138, IE may throw an exception when accessing
// a field from window.location if document.domain has been set
try {
ajaxLocation = location.href;
} catch( e ) {
// Use the href attribute of an A element
// since IE will modify it given document.location
ajaxLocation = document.createElement( "a" );
ajaxLocation.href = "";
ajaxLocation = ajaxLocation.href;
}
// Segment location into parts
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
function addToPrefiltersOrTransports( structure ) {
// dataTypeExpression is optional and defaults to "*"
return function( dataTypeExpression, func ) {
if ( typeof dataTypeExpression !== "string" ) {
func = dataTypeExpression;
dataTypeExpression = "*";
}
if ( jQuery.isFunction( func ) ) {
var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ),
i = 0,
length = dataTypes.length,
dataType,
list,
placeBefore;
// For each dataType in the dataTypeExpression
for ( ; i < length; i++ ) {
dataType = dataTypes[ i ];
// We control if we're asked to add before
// any existing element
placeBefore = /^\+/.test( dataType );
if ( placeBefore ) {
dataType = dataType.substr( 1 ) || "*";
}
list = structure[ dataType ] = structure[ dataType ] || [];
// then we add to the structure accordingly
list[ placeBefore ? "unshift" : "push" ]( func );
}
}
};
}
// Base inspection function for prefilters and transports
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
dataType /* internal */, inspected /* internal */ ) {
dataType = dataType || options.dataTypes[ 0 ];
inspected = inspected || {};
inspected[ dataType ] = true;
var list = structure[ dataType ],
i = 0,
length = list ? list.length : 0,
executeOnly = ( structure === prefilters ),
selection;
for ( ; i < length && ( executeOnly || !selection ); i++ ) {
selection = list[ i ]( options, originalOptions, jqXHR );
// If we got redirected to another dataType
// we try there if executing only and not done already
if ( typeof selection === "string" ) {
if ( !executeOnly || inspected[ selection ] ) {
selection = undefined;
} else {
options.dataTypes.unshift( selection );
selection = inspectPrefiltersOrTransports(
structure, options, originalOptions, jqXHR, selection, inspected );
}
}
}
// If we're only executing or nothing was selected
// we try the catchall dataType if not done already
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
selection = inspectPrefiltersOrTransports(
structure, options, originalOptions, jqXHR, "*", inspected );
}
// unnecessary when only executing (prefilters)
// but it'll be ignored by the caller in that case
return selection;
}
// A special extend for ajax options
// that takes "flat" options (not to be deep extended)
// Fixes #9887
function ajaxExtend( target, src ) {
var key, deep,
flatOptions = jQuery.ajaxSettings.flatOptions || {};
for ( key in src ) {
if ( src[ key ] !== undefined ) {
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
}
}
if ( deep ) {
jQuery.extend( true, target, deep );
}
}
jQuery.fn.extend({
load: function( url, params, callback ) {
if ( typeof url !== "string" && _load ) {
return _load.apply( this, arguments );
// Don't do a request if no elements are being requested
} else if ( !this.length ) {
return this;
}
var off = url.indexOf( " " );
if ( off >= 0 ) {
var selector = url.slice( off, url.length );
url = url.slice( 0, off );
}
// Default to a GET request
var type = "GET";
// If the second parameter was provided
if ( params ) {
// If it's a function
if ( jQuery.isFunction( params ) ) {
// We assume that it's the callback
callback = params;
params = undefined;
// Otherwise, build a param string
} else if ( typeof params === "object" ) {
params = jQuery.param( params, jQuery.ajaxSettings.traditional );
type = "POST";
}
}
var self = this;
// Request the remote document
jQuery.ajax({
url: url,
type: type,
dataType: "html",
data: params,
// Complete callback (responseText is used internally)
complete: function( jqXHR, status, responseText ) {
// Store the response as specified by the jqXHR object
responseText = jqXHR.responseText;
// If successful, inject the HTML into all the matched elements
if ( jqXHR.isResolved() ) {
// #4825: Get the actual response in case
// a dataFilter is present in ajaxSettings
jqXHR.done(function( r ) {
responseText = r;
});
// See if a selector was specified
self.html( selector ?
// Create a dummy div to hold the results
jQuery("<div>")
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.append(responseText.replace(rscript, ""))
// Locate the specified elements
.find(selector) :
// If not, just inject the full result
responseText );
}
if ( callback ) {
self.each( callback, [ responseText, status, jqXHR ] );
}
}
});
return this;
},
serialize: function() {
return jQuery.param( this.serializeArray() );
},
serializeArray: function() {
return this.map(function(){
return this.elements ? jQuery.makeArray( this.elements ) : this;
})
.filter(function(){
return this.name && !this.disabled &&
( this.checked || rselectTextarea.test( this.nodeName ) ||
rinput.test( this.type ) );
})
.map(function( i, elem ){
var val = jQuery( this ).val();
return val == null ?
null :
jQuery.isArray( val ) ?
jQuery.map( val, function( val, i ){
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
}) :
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
}).get();
}
});
// Attach a bunch of functions for handling common AJAX events
jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split( " " ), function( i, o ){
jQuery.fn[ o ] = function( f ){
return this.on( o, f );
};
});
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
type: method,
url: url,
data: data,
success: callback,
dataType: type
});
};
});
jQuery.extend({
getScript: function( url, callback ) {
return jQuery.get( url, undefined, callback, "script" );
},
getJSON: function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
},
// Creates a full fledged settings object into target
// with both ajaxSettings and settings fields.
// If target is omitted, writes into ajaxSettings.
ajaxSetup: function( target, settings ) {
if ( settings ) {
// Building a settings object
ajaxExtend( target, jQuery.ajaxSettings );
} else {
// Extending ajaxSettings
settings = target;
target = jQuery.ajaxSettings;
}
ajaxExtend( target, settings );
return target;
},
ajaxSettings: {
url: ajaxLocation,
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
global: true,
type: "GET",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
processData: true,
async: true,
/*
timeout: 0,
data: null,
dataType: null,
username: null,
password: null,
cache: null,
traditional: false,
headers: {},
*/
accepts: {
xml: "application/xml, text/xml",
html: "text/html",
text: "text/plain",
json: "application/json, text/javascript",
"*": allTypes
},
contents: {
xml: /xml/,
html: /html/,
json: /json/
},
responseFields: {
xml: "responseXML",
text: "responseText"
},
// List of data converters
// 1) key format is "source_type destination_type" (a single space in-between)
// 2) the catchall symbol "*" can be used for source_type
converters: {
// Convert anything to text
"* text": window.String,
// Text to html (true = no transformation)
"text html": true,
// Evaluate text as a json expression
"text json": jQuery.parseJSON,
// Parse text as xml
"text xml": jQuery.parseXML
},
// For options that shouldn't be deep extended:
// you can add your own custom options here if
// and when you create one that shouldn't be
// deep extended (see ajaxExtend)
flatOptions: {
context: true,
url: true
}
},
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
ajaxTransport: addToPrefiltersOrTransports( transports ),
// Main method
ajax: function( url, options ) {
// If url is an object, simulate pre-1.5 signature
if ( typeof url === "object" ) {
options = url;
url = undefined;
}
// Force options to be an object
options = options || {};
var // Create the final options object
s = jQuery.ajaxSetup( {}, options ),
// Callbacks context
callbackContext = s.context || s,
// Context for global events
// It's the callbackContext if one was provided in the options
// and if it's a DOM node or a jQuery collection
globalEventContext = callbackContext !== s &&
( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
jQuery( callbackContext ) : jQuery.event,
// Deferreds
deferred = jQuery.Deferred(),
completeDeferred = jQuery.Callbacks( "once memory" ),
// Status-dependent callbacks
statusCode = s.statusCode || {},
// ifModified key
ifModifiedKey,
// Headers (they are sent all at once)
requestHeaders = {},
requestHeadersNames = {},
// Response headers
responseHeadersString,
responseHeaders,
// transport
transport,
// timeout handle
timeoutTimer,
// Cross-domain detection vars
parts,
// The jqXHR state
state = 0,
// To know if global events are to be dispatched
fireGlobals,
// Loop variable
i,
// Fake xhr
jqXHR = {
readyState: 0,
// Caches the header
setRequestHeader: function( name, value ) {
if ( !state ) {
var lname = name.toLowerCase();
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
requestHeaders[ name ] = value;
}
return this;
},
// Raw string
getAllResponseHeaders: function() {
return state === 2 ? responseHeadersString : null;
},
// Builds headers hashtable if needed
getResponseHeader: function( key ) {
var match;
if ( state === 2 ) {
if ( !responseHeaders ) {
responseHeaders = {};
while( ( match = rheaders.exec( responseHeadersString ) ) ) {
responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
}
}
match = responseHeaders[ key.toLowerCase() ];
}
return match === undefined ? null : match;
},
// Overrides response content-type header
overrideMimeType: function( type ) {
if ( !state ) {
s.mimeType = type;
}
return this;
},
// Cancel the request
abort: function( statusText ) {
statusText = statusText || "abort";
if ( transport ) {
transport.abort( statusText );
}
done( 0, statusText );
return this;
}
};
// Callback for when everything is done
// It is defined here because jslint complains if it is declared
// at the end of the function (which would be more logical and readable)
function done( status, nativeStatusText, responses, headers ) {
// Called once
if ( state === 2 ) {
return;
}
// State is "done" now
state = 2;
// Clear timeout if it exists
if ( timeoutTimer ) {
clearTimeout( timeoutTimer );
}
// Dereference transport for early garbage collection
// (no matter how long the jqXHR object will be used)
transport = undefined;
// Cache response headers
responseHeadersString = headers || "";
// Set readyState
jqXHR.readyState = status > 0 ? 4 : 0;
var isSuccess,
success,
error,
statusText = nativeStatusText,
response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
lastModified,
etag;
// If successful, handle type chaining
if ( status >= 200 && status < 300 || status === 304 ) {
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
jQuery.lastModified[ ifModifiedKey ] = lastModified;
}
if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
jQuery.etag[ ifModifiedKey ] = etag;
}
}
// If not modified
if ( status === 304 ) {
statusText = "notmodified";
isSuccess = true;
// If we have data
} else {
try {
success = ajaxConvert( s, response );
statusText = "success";
isSuccess = true;
} catch(e) {
// We have a parsererror
statusText = "parsererror";
error = e;
}
}
} else {
// We extract error from statusText
// then normalize statusText and status for non-aborts
error = statusText;
if ( !statusText || status ) {
statusText = "error";
if ( status < 0 ) {
status = 0;
}
}
}
// Set data for the fake xhr object
jqXHR.status = status;
jqXHR.statusText = "" + ( nativeStatusText || statusText );
// Success/Error
if ( isSuccess ) {
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
} else {
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
}
// Status-dependent callbacks
jqXHR.statusCode( statusCode );
statusCode = undefined;
if ( fireGlobals ) {
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
[ jqXHR, s, isSuccess ? success : error ] );
}
// Complete
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );
}
}
}
// Attach deferreds
deferred.promise( jqXHR );
jqXHR.success = jqXHR.done;
jqXHR.error = jqXHR.fail;
jqXHR.complete = completeDeferred.add;
// Status-dependent callbacks
jqXHR.statusCode = function( map ) {
if ( map ) {
var tmp;
if ( state < 2 ) {
for ( tmp in map ) {
statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
}
} else {
tmp = map[ jqXHR.status ];
jqXHR.then( tmp, tmp );
}
}
return this;
};
// Remove hash character (#7531: and string promotion)
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
// We also use the url parameter if available
s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
// Extract dataTypes list
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
// Determine if a cross-domain request is in order
if ( s.crossDomain == null ) {
parts = rurl.exec( s.url.toLowerCase() );
s.crossDomain = !!( parts &&
( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
);
}
// Convert data if not already a string
if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
}
// Apply prefilters
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
// If request was aborted inside a prefilter, stop there
if ( state === 2 ) {
return false;
}
// We can fire global events as of now if asked to
fireGlobals = s.global;
// Uppercase the type
s.type = s.type.toUpperCase();
// Determine if request has content
s.hasContent = !rnoContent.test( s.type );
// Watch for a new set of requests
if ( fireGlobals && jQuery.active++ === 0 ) {
jQuery.event.trigger( "ajaxStart" );
}
// More options handling for requests with no content
if ( !s.hasContent ) {
// If data is available, append data to url
if ( s.data ) {
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
// #9682: remove data so that it's not used in an eventual retry
delete s.data;
}
// Get ifModifiedKey before adding the anti-cache parameter
ifModifiedKey = s.url;
// Add anti-cache in url if needed
if ( s.cache === false ) {
var ts = jQuery.now(),
// try replacing _= if it is there
ret = s.url.replace( rts, "$1_=" + ts );
// if nothing was replaced, add timestamp to the end
s.url = ret + ( ( ret === s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "" );
}
}
// Set the correct header, if data is being sent
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
jqXHR.setRequestHeader( "Content-Type", s.contentType );
}
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
ifModifiedKey = ifModifiedKey || s.url;
if ( jQuery.lastModified[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
}
if ( jQuery.etag[ ifModifiedKey ] ) {
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
}
}
// Set the Accepts header for the server, depending on the dataType
jqXHR.setRequestHeader(
"Accept",
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
s.accepts[ "*" ]
);
// Check for headers option
for ( i in s.headers ) {
jqXHR.setRequestHeader( i, s.headers[ i ] );
}
// Allow custom headers/mimetypes and early abort
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
// Abort if not done already
jqXHR.abort();
return false;
}
// Install callbacks on deferreds
for ( i in { success: 1, error: 1, complete: 1 } ) {
jqXHR[ i ]( s[ i ] );
}
// Get transport
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
// If no transport, we auto-abort
if ( !transport ) {
done( -1, "No Transport" );
} else {
jqXHR.readyState = 1;
// Send global event
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
}
// Timeout
if ( s.async && s.timeout > 0 ) {
timeoutTimer = setTimeout( function(){
jqXHR.abort( "timeout" );
}, s.timeout );
}
try {
state = 1;
transport.send( requestHeaders, done );
} catch (e) {
// Propagate exception as error if not done
if ( state < 2 ) {
done( -1, e );
// Simply rethrow otherwise
} else {
throw e;
}
}
}
return jqXHR;
},
// Serialize an array of form elements or a set of
// key/values into a query string
param: function( a, traditional ) {
var s = [],
add = function( key, value ) {
// If value is a function, invoke it and return its value
value = jQuery.isFunction( value ) ? value() : value;
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
};
// Set traditional to true for jQuery <= 1.3.2 behavior.
if ( traditional === undefined ) {
traditional = jQuery.ajaxSettings.traditional;
}
// If an array was passed in, assume that it is an array of form elements.
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
// Serialize the form elements
jQuery.each( a, function() {
add( this.name, this.value );
});
} else {
// If traditional, encode the "old" way (the way 1.3.2 or older
// did it), otherwise encode params recursively.
for ( var prefix in a ) {
buildParams( prefix, a[ prefix ], traditional, add );
}
}
// Return the resulting serialization
return s.join( "&" ).replace( r20, "+" );
}
});
function buildParams( prefix, obj, traditional, add ) {
if ( jQuery.isArray( obj ) ) {
// Serialize array item.
jQuery.each( obj, function( i, v ) {
if ( traditional || rbracket.test( prefix ) ) {
// Treat each array item as a scalar.
add( prefix, v );
} else {
// If array item is non-scalar (array or object), encode its
// numeric index to resolve deserialization ambiguity issues.
// Note that rack (as of 1.0.0) can't currently deserialize
// nested arrays properly, and attempting to do so may cause
// a server error. Possible fixes are to modify rack's
// deserialization algorithm or to provide an option or flag
// to force array serialization to be shallow.
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
}
});
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
// Serialize object item.
for ( var name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}
} else {
// Serialize scalar item.
add( prefix, obj );
}
}
// This is still on the jQuery object... for now
// Want to move this to jQuery.ajax some day
jQuery.extend({
// Counter for holding the number of active queries
active: 0,
// Last-Modified header cache for next request
lastModified: {},
etag: {}
});
/* Handles responses to an ajax request:
* - sets all responseXXX fields accordingly
* - finds the right dataType (mediates between content-type and expected dataType)
* - returns the corresponding response
*/
function ajaxHandleResponses( s, jqXHR, responses ) {
var contents = s.contents,
dataTypes = s.dataTypes,
responseFields = s.responseFields,
ct,
type,
finalDataType,
firstDataType;
// Fill responseXXX fields
for ( type in responseFields ) {
if ( type in responses ) {
jqXHR[ responseFields[type] ] = responses[ type ];
}
}
// Remove auto dataType and get content-type in the process
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
}
}
// Check if we're dealing with a known content-type
if ( ct ) {
for ( type in contents ) {
if ( contents[ type ] && contents[ type ].test( ct ) ) {
dataTypes.unshift( type );
break;
}
}
}
// Check to see if we have a response for the expected dataType
if ( dataTypes[ 0 ] in responses ) {
finalDataType = dataTypes[ 0 ];
} else {
// Try convertible dataTypes
for ( type in responses ) {
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
finalDataType = type;
break;
}
if ( !firstDataType ) {
firstDataType = type;
}
}
// Or just use first one
finalDataType = finalDataType || firstDataType;
}
// If we found a dataType
// We add the dataType to the list if needed
// and return the corresponding response
if ( finalDataType ) {
if ( finalDataType !== dataTypes[ 0 ] ) {
dataTypes.unshift( finalDataType );
}
return responses[ finalDataType ];
}
}
// Chain conversions given the request and the original response
function ajaxConvert( s, response ) {
// Apply the dataFilter if provided
if ( s.dataFilter ) {
response = s.dataFilter( response, s.dataType );
}
var dataTypes = s.dataTypes,
converters = {},
i,
key,
length = dataTypes.length,
tmp,
// Current and previous dataTypes
current = dataTypes[ 0 ],
prev,
// Conversion expression
conversion,
// Conversion function
conv,
// Conversion functions (transitive conversion)
conv1,
conv2;
// For each dataType in the chain
for ( i = 1; i < length; i++ ) {
// Create converters map
// with lowercased keys
if ( i === 1 ) {
for ( key in s.converters ) {
if ( typeof key === "string" ) {
converters[ key.toLowerCase() ] = s.converters[ key ];
}
}
}
// Get the dataTypes
prev = current;
current = dataTypes[ i ];
// If current is auto dataType, update it to prev
if ( current === "*" ) {
current = prev;
// If no auto and dataTypes are actually different
} else if ( prev !== "*" && prev !== current ) {
// Get the converter
conversion = prev + " " + current;
conv = converters[ conversion ] || converters[ "* " + current ];
// If there is no direct converter, search transitively
if ( !conv ) {
conv2 = undefined;
for ( conv1 in converters ) {
tmp = conv1.split( " " );
if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
conv2 = converters[ tmp[1] + " " + current ];
if ( conv2 ) {
conv1 = converters[ conv1 ];
if ( conv1 === true ) {
conv = conv2;
} else if ( conv2 === true ) {
conv = conv1;
}
break;
}
}
}
}
// If we found no converter, dispatch an error
if ( !( conv || conv2 ) ) {
jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
}
// If found converter is not an equivalence
if ( conv !== true ) {
// Convert with 1 or 2 converters accordingly
response = conv ? conv( response ) : conv2( conv1(response) );
}
}
}
return response;
}
var jsc = jQuery.now(),
jsre = /(\=)\?(&|$)|\?\?/i;
// Default jsonp settings
jQuery.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
return jQuery.expando + "_" + ( jsc++ );
}
});
// Detect, normalize options and install callbacks for jsonp requests
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
var inspectData = ( typeof s.data === "string" ) && /^application\/x\-www\-form\-urlencoded/.test( s.contentType );
if ( s.dataTypes[ 0 ] === "jsonp" ||
s.jsonp !== false && ( jsre.test( s.url ) ||
inspectData && jsre.test( s.data ) ) ) {
var responseContainer,
jsonpCallback = s.jsonpCallback =
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
previous = window[ jsonpCallback ],
url = s.url,
data = s.data,
replace = "$1" + jsonpCallback + "$2";
if ( s.jsonp !== false ) {
url = url.replace( jsre, replace );
if ( s.url === url ) {
if ( inspectData ) {
data = data.replace( jsre, replace );
}
if ( s.data === data ) {
// Add callback manually
url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
}
}
}
s.url = url;
s.data = data;
// Install callback
window[ jsonpCallback ] = function( response ) {
responseContainer = [ response ];
};
// Clean-up function
jqXHR.always(function() {
// Set callback back to previous value
window[ jsonpCallback ] = previous;
// Call if it was a function and we have a response
if ( responseContainer && jQuery.isFunction( previous ) ) {
window[ jsonpCallback ]( responseContainer[ 0 ] );
}
});
// Use data converter to retrieve json after script execution
s.converters["script json"] = function() {
if ( !responseContainer ) {
jQuery.error( jsonpCallback + " was not called" );
}
return responseContainer[ 0 ];
};
// force json dataType
s.dataTypes[ 0 ] = "json";
// Delegate to script
return "script";
}
});
// Install script dataType
jQuery.ajaxSetup({
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
contents: {
script: /javascript|ecmascript/
},
converters: {
"text script": function( text ) {
jQuery.globalEval( text );
return text;
}
}
});
// Handle cache's special case and global
jQuery.ajaxPrefilter( "script", function( s ) {
if ( s.cache === undefined ) {
s.cache = false;
}
if ( s.crossDomain ) {
s.type = "GET";
s.global = false;
}
});
// Bind script tag hack transport
jQuery.ajaxTransport( "script", function(s) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
var script,
head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
return {
send: function( _, callback ) {
script = document.createElement( "script" );
script.async = "async";
if ( s.scriptCharset ) {
script.charset = s.scriptCharset;
}
script.src = s.url;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function( _, isAbort ) {
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
// Remove the script
if ( head && script.parentNode ) {
head.removeChild( script );
}
// Dereference the script
script = undefined;
// Callback if not abort
if ( !isAbort ) {
callback( 200, "success" );
}
}
};
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild );
},
abort: function() {
if ( script ) {
script.onload( 0, 1 );
}
}
};
}
});
var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
xhrOnUnloadAbort = window.ActiveXObject ? function() {
// Abort all pending requests
for ( var key in xhrCallbacks ) {
xhrCallbacks[ key ]( 0, 1 );
}
} : false,
xhrId = 0,
xhrCallbacks;
// Functions to create xhrs
function createStandardXHR() {
try {
return new window.XMLHttpRequest();
} catch( e ) {}
}
function createActiveXHR() {
try {
return new window.ActiveXObject( "Microsoft.XMLHTTP" );
} catch( e ) {}
}
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
* so we use the ActiveXObject when it is available
* Additionally XMLHttpRequest can be disabled in IE7/IE8 so
* we need a fallback.
*/
function() {
return !this.isLocal && createStandardXHR() || createActiveXHR();
} :
// For all other browsers, use the standard XMLHttpRequest object
createStandardXHR;
// Determine support properties
(function( xhr ) {
jQuery.extend( jQuery.support, {
ajax: !!xhr,
cors: !!xhr && ( "withCredentials" in xhr )
});
})( jQuery.ajaxSettings.xhr() );
// Create transport if the browser can provide an xhr
if ( jQuery.support.ajax ) {
jQuery.ajaxTransport(function( s ) {
// Cross domain only allowed if supported through XMLHttpRequest
if ( !s.crossDomain || jQuery.support.cors ) {
var callback;
return {
send: function( headers, complete ) {
// Get a new xhr
var xhr = s.xhr(),
handle,
i;
// Open the socket
// Passing null username, generates a login popup on Opera (#2865)
if ( s.username ) {
xhr.open( s.type, s.url, s.async, s.username, s.password );
} else {
xhr.open( s.type, s.url, s.async );
}
// Apply custom fields if provided
if ( s.xhrFields ) {
for ( i in s.xhrFields ) {
xhr[ i ] = s.xhrFields[ i ];
}
}
// Override mime type if needed
if ( s.mimeType && xhr.overrideMimeType ) {
xhr.overrideMimeType( s.mimeType );
}
// X-Requested-With header
// For cross-domain requests, seeing as conditions for a preflight are
// akin to a jigsaw puzzle, we simply never set it to be sure.
// (it can always be set on a per-request basis or even using ajaxSetup)
// For same-domain requests, won't change header if already provided.
if ( !s.crossDomain && !headers["X-Requested-With"] ) {
headers[ "X-Requested-With" ] = "XMLHttpRequest";
}
// Need an extra try/catch for cross domain requests in Firefox 3
try {
for ( i in headers ) {
xhr.setRequestHeader( i, headers[ i ] );
}
} catch( _ ) {}
// Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
xhr.send( ( s.hasContent && s.data ) || null );
// Listener
callback = function( _, isAbort ) {
var status,
statusText,
responseHeaders,
responses,
xml;
// Firefox throws exceptions when accessing properties
// of an xhr when a network error occured
// http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
try {
// Was never called and is aborted or complete
if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
// Only called once
callback = undefined;
// Do not keep as active anymore
if ( handle ) {
xhr.onreadystatechange = jQuery.noop;
if ( xhrOnUnloadAbort ) {
delete xhrCallbacks[ handle ];
}
}
// If it's an abort
if ( isAbort ) {
// Abort it manually if needed
if ( xhr.readyState !== 4 ) {
xhr.abort();
}
} else {
status = xhr.status;
responseHeaders = xhr.getAllResponseHeaders();
responses = {};
xml = xhr.responseXML;
// Construct response list
if ( xml && xml.documentElement /* #4958 */ ) {
responses.xml = xml;
}
// When requesting binary data, IE6-9 will throw an exception
// on any attempt to access responseText (#11426)
try {
responses.text = xhr.responseText;
} catch( _ ) {
}
// Firefox throws an exception when accessing
// statusText for faulty cross-domain requests
try {
statusText = xhr.statusText;
} catch( e ) {
// We normalize with Webkit giving an empty statusText
statusText = "";
}
// Filter status for non standard behaviors
// If the request is local and we have data: assume a success
// (success with no data won't get notified, that's the best we
// can do given current implementations)
if ( !status && s.isLocal && !s.crossDomain ) {
status = responses.text ? 200 : 404;
// IE - #1450: sometimes returns 1223 when it should be 204
} else if ( status === 1223 ) {
status = 204;
}
}
}
} catch( firefoxAccessException ) {
if ( !isAbort ) {
complete( -1, firefoxAccessException );
}
}
// Call complete if needed
if ( responses ) {
complete( status, statusText, responses, responseHeaders );
}
};
// if we're in sync mode or it's in cache
// and has been retrieved directly (IE6 & IE7)
// we need to manually fire the callback
if ( !s.async || xhr.readyState === 4 ) {
callback();
} else {
handle = ++xhrId;
if ( xhrOnUnloadAbort ) {
// Create the active xhrs callbacks list if needed
// and attach the unload handler
if ( !xhrCallbacks ) {
xhrCallbacks = {};
jQuery( window ).unload( xhrOnUnloadAbort );
}
// Add to list of active xhrs callbacks
xhrCallbacks[ handle ] = callback;
}
xhr.onreadystatechange = callback;
}
},
abort: function() {
if ( callback ) {
callback(0,1);
}
}
};
}
});
}
var elemdisplay = {},
iframe, iframeDoc,
rfxtypes = /^(?:toggle|show|hide)$/,
rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
timerId,
fxAttrs = [
// height animations
[ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
// width animations
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations
[ "opacity" ]
],
fxNow;
jQuery.fn.extend({
show: function( speed, easing, callback ) {
var elem, display;
if ( speed || speed === 0 ) {
return this.animate( genFx("show", 3), speed, easing, callback );
} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
elem = this[ i ];
if ( elem.style ) {
display = elem.style.display;
// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
display = elem.style.display = "";
}
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( (display === "" && jQuery.css(elem, "display") === "none") ||
!jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
}
}
}
// Set the display of most of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
elem = this[ i ];
if ( elem.style ) {
display = elem.style.display;
if ( display === "" || display === "none" ) {
elem.style.display = jQuery._data( elem, "olddisplay" ) || "";
}
}
}
return this;
}
},
hide: function( speed, easing, callback ) {
if ( speed || speed === 0 ) {
return this.animate( genFx("hide", 3), speed, easing, callback);
} else {
var elem, display,
i = 0,
j = this.length;
for ( ; i < j; i++ ) {
elem = this[i];
if ( elem.style ) {
display = jQuery.css( elem, "display" );
if ( display !== "none" && !jQuery._data( elem, "olddisplay" ) ) {
jQuery._data( elem, "olddisplay", display );
}
}
}
// Set the display of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
if ( this[i].style ) {
this[i].style.display = "none";
}
}
return this;
}
},
// Save the old toggle function
_toggle: jQuery.fn.toggle,
toggle: function( fn, fn2, callback ) {
var bool = typeof fn === "boolean";
if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
this._toggle.apply( this, arguments );
} else if ( fn == null || bool ) {
this.each(function() {
var state = bool ? fn : jQuery(this).is(":hidden");
jQuery(this)[ state ? "show" : "hide" ]();
});
} else {
this.animate(genFx("toggle", 3), fn, fn2, callback);
}
return this;
},
fadeTo: function( speed, to, easing, callback ) {
return this.filter(":hidden").css("opacity", 0).show().end()
.animate({opacity: to}, speed, easing, callback);
},
animate: function( prop, speed, easing, callback ) {
var optall = jQuery.speed( speed, easing, callback );
if ( jQuery.isEmptyObject( prop ) ) {
return this.each( optall.complete, [ false ] );
}
// Do not change referenced properties as per-property easing will be lost
prop = jQuery.extend( {}, prop );
function doAnimation() {
// XXX 'this' does not always have a nodeName when running the
// test suite
if ( optall.queue === false ) {
jQuery._mark( this );
}
var opt = jQuery.extend( {}, optall ),
isElement = this.nodeType === 1,
hidden = isElement && jQuery(this).is(":hidden"),
name, val, p, e, hooks, replace,
parts, start, end, unit,
method;
// will store per property easing and be used to determine when an animation is complete
opt.animatedProperties = {};
// first pass over propertys to expand / normalize
for ( p in prop ) {
name = jQuery.camelCase( p );
if ( p !== name ) {
prop[ name ] = prop[ p ];
delete prop[ p ];
}
if ( ( hooks = jQuery.cssHooks[ name ] ) && "expand" in hooks ) {
replace = hooks.expand( prop[ name ] );
delete prop[ name ];
// not quite $.extend, this wont overwrite keys already present.
// also - reusing 'p' from above because we have the correct "name"
for ( p in replace ) {
if ( ! ( p in prop ) ) {
prop[ p ] = replace[ p ];
}
}
}
}
for ( name in prop ) {
val = prop[ name ];
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
if ( jQuery.isArray( val ) ) {
opt.animatedProperties[ name ] = val[ 1 ];
val = prop[ name ] = val[ 0 ];
} else {
opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || 'swing';
}
if ( val === "hide" && hidden || val === "show" && !hidden ) {
return opt.complete.call( this );
}
if ( isElement && ( name === "height" || name === "width" ) ) {
// Make sure that nothing sneaks out
// Record all 3 overflow attributes because IE does not
// change the overflow attribute when overflowX and
// overflowY are set to the same value
opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
// Set display property to inline-block for height/width
// animations on inline elements that are having width/height animated
if ( jQuery.css( this, "display" ) === "inline" &&
jQuery.css( this, "float" ) === "none" ) {
// inline-level elements accept inline-block;
// block-level elements need to be inline with layout
if ( !jQuery.support.inlineBlockNeedsLayout || defaultDisplay( this.nodeName ) === "inline" ) {
this.style.display = "inline-block";
} else {
this.style.zoom = 1;
}
}
}
}
if ( opt.overflow != null ) {
this.style.overflow = "hidden";
}
for ( p in prop ) {
e = new jQuery.fx( this, opt, p );
val = prop[ p ];
if ( rfxtypes.test( val ) ) {
// Tracks whether to show or hide based on private
// data attached to the element
method = jQuery._data( this, "toggle" + p ) || ( val === "toggle" ? hidden ? "show" : "hide" : 0 );
if ( method ) {
jQuery._data( this, "toggle" + p, method === "show" ? "hide" : "show" );
e[ method ]();
} else {
e[ val ]();
}
} else {
parts = rfxnum.exec( val );
start = e.cur();
if ( parts ) {
end = parseFloat( parts[2] );
unit = parts[3] || ( jQuery.cssNumber[ p ] ? "" : "px" );
// We need to compute starting value
if ( unit !== "px" ) {
jQuery.style( this, p, (end || 1) + unit);
start = ( (end || 1) / e.cur() ) * start;
jQuery.style( this, p, start + unit);
}
// If a +=/-= token was provided, we're doing a relative animation
if ( parts[1] ) {
end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
}
e.custom( start, end, unit );
} else {
e.custom( start, val, "" );
}
}
}
// For JS strict compliance
return true;
}
return optall.queue === false ?
this.each( doAnimation ) :
this.queue( optall.queue, doAnimation );
},
stop: function( type, clearQueue, gotoEnd ) {
if ( typeof type !== "string" ) {
gotoEnd = clearQueue;
clearQueue = type;
type = undefined;
}
if ( clearQueue && type !== false ) {
this.queue( type || "fx", [] );
}
return this.each(function() {
var index,
hadTimers = false,
timers = jQuery.timers,
data = jQuery._data( this );
// clear marker counters if we know they won't be
if ( !gotoEnd ) {
jQuery._unmark( true, this );
}
function stopQueue( elem, data, index ) {
var hooks = data[ index ];
jQuery.removeData( elem, index, true );
hooks.stop( gotoEnd );
}
if ( type == null ) {
for ( index in data ) {
if ( data[ index ] && data[ index ].stop && index.indexOf(".run") === index.length - 4 ) {
stopQueue( this, data, index );
}
}
} else if ( data[ index = type + ".run" ] && data[ index ].stop ){
stopQueue( this, data, index );
}
for ( index = timers.length; index--; ) {
if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
if ( gotoEnd ) {
// force the next step to be the last
timers[ index ]( true );
} else {
timers[ index ].saveState();
}
hadTimers = true;
timers.splice( index, 1 );
}
}
// start the next in the queue if the last step wasn't forced
// timers currently will call their complete callbacks, which will dequeue
// but only if they were gotoEnd
if ( !( gotoEnd && hadTimers ) ) {
jQuery.dequeue( this, type );
}
});
}
});
// Animations created synchronously will run synchronously
function createFxNow() {
setTimeout( clearFxNow, 0 );
return ( fxNow = jQuery.now() );
}
function clearFxNow() {
fxNow = undefined;
}
// Generate parameters to create a standard animation
function genFx( type, num ) {
var obj = {};
jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice( 0, num )), function() {
obj[ this ] = type;
});
return obj;
}
// Generate shortcuts for custom animations
jQuery.each({
slideDown: genFx( "show", 1 ),
slideUp: genFx( "hide", 1 ),
slideToggle: genFx( "toggle", 1 ),
fadeIn: { opacity: "show" },
fadeOut: { opacity: "hide" },
fadeToggle: { opacity: "toggle" }
}, function( name, props ) {
jQuery.fn[ name ] = function( speed, easing, callback ) {
return this.animate( props, speed, easing, callback );
};
});
jQuery.extend({
speed: function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
complete: fn || !fn && easing ||
jQuery.isFunction( speed ) && speed,
duration: speed,
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
};
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
// normalize opt.queue - true/undefined/null -> "fx"
if ( opt.queue == null || opt.queue === true ) {
opt.queue = "fx";
}
// Queueing
opt.old = opt.complete;
opt.complete = function( noUnmark ) {
if ( jQuery.isFunction( opt.old ) ) {
opt.old.call( this );
}
if ( opt.queue ) {
jQuery.dequeue( this, opt.queue );
} else if ( noUnmark !== false ) {
jQuery._unmark( this );
}
};
return opt;
},
easing: {
linear: function( p ) {
return p;
},
swing: function( p ) {
return ( -Math.cos( p*Math.PI ) / 2 ) + 0.5;
}
},
timers: [],
fx: function( elem, options, prop ) {
this.options = options;
this.elem = elem;
this.prop = prop;
options.orig = options.orig || {};
}
});
jQuery.fx.prototype = {
// Simple function for setting a style value
update: function() {
if ( this.options.step ) {
this.options.step.call( this.elem, this.now, this );
}
( jQuery.fx.step[ this.prop ] || jQuery.fx.step._default )( this );
},
// Get the current size
cur: function() {
if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) {
return this.elem[ this.prop ];
}
var parsed,
r = jQuery.css( this.elem, this.prop );
// Empty strings, null, undefined and "auto" are converted to 0,
// complex values such as "rotate(1rad)" are returned as is,
// simple values such as "10px" are parsed to Float.
return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
},
// Start an animation from one number to another
custom: function( from, to, unit ) {
var self = this,
fx = jQuery.fx;
this.startTime = fxNow || createFxNow();
this.end = to;
this.now = this.start = from;
this.pos = this.state = 0;
this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
function t( gotoEnd ) {
return self.step( gotoEnd );
}
t.queue = this.options.queue;
t.elem = this.elem;
t.saveState = function() {
if ( jQuery._data( self.elem, "fxshow" + self.prop ) === undefined ) {
if ( self.options.hide ) {
jQuery._data( self.elem, "fxshow" + self.prop, self.start );
} else if ( self.options.show ) {
jQuery._data( self.elem, "fxshow" + self.prop, self.end );
}
}
};
if ( t() && jQuery.timers.push(t) && !timerId ) {
timerId = setInterval( fx.tick, fx.interval );
}
},
// Simple 'show' function
show: function() {
var dataShow = jQuery._data( this.elem, "fxshow" + this.prop );
// Remember where we started, so that we can go back to it later
this.options.orig[ this.prop ] = dataShow || jQuery.style( this.elem, this.prop );
this.options.show = true;
// Begin the animation
// Make sure that we start at a small width/height to avoid any flash of content
if ( dataShow !== undefined ) {
// This show is picking up where a previous hide or show left off
this.custom( this.cur(), dataShow );
} else {
this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() );
}
// Start by showing the element
jQuery( this.elem ).show();
},
// Simple 'hide' function
hide: function() {
// Remember where we started, so that we can go back to it later
this.options.orig[ this.prop ] = jQuery._data( this.elem, "fxshow" + this.prop ) || jQuery.style( this.elem, this.prop );
this.options.hide = true;
// Begin the animation
this.custom( this.cur(), 0 );
},
// Each step of an animation
step: function( gotoEnd ) {
var p, n, complete,
t = fxNow || createFxNow(),
done = true,
elem = this.elem,
options = this.options;
if ( gotoEnd || t >= options.duration + this.startTime ) {
this.now = this.end;
this.pos = this.state = 1;
this.update();
options.animatedProperties[ this.prop ] = true;
for ( p in options.animatedProperties ) {
if ( options.animatedProperties[ p ] !== true ) {
done = false;
}
}
if ( done ) {
// Reset the overflow
if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
jQuery.each( [ "", "X", "Y" ], function( index, value ) {
elem.style[ "overflow" + value ] = options.overflow[ index ];
});
}
// Hide the element if the "hide" operation was done
if ( options.hide ) {
jQuery( elem ).hide();
}
// Reset the properties, if the item has been hidden or shown
if ( options.hide || options.show ) {
for ( p in options.animatedProperties ) {
jQuery.style( elem, p, options.orig[ p ] );
jQuery.removeData( elem, "fxshow" + p, true );
// Toggle data is no longer needed
jQuery.removeData( elem, "toggle" + p, true );
}
}
// Execute the complete function
// in the event that the complete function throws an exception
// we must ensure it won't be called twice. #5684
complete = options.complete;
if ( complete ) {
options.complete = false;
complete.call( elem );
}
}
return false;
} else {
// classical easing cannot be used with an Infinity duration
if ( options.duration == Infinity ) {
this.now = t;
} else {
n = t - this.startTime;
this.state = n / options.duration;
// Perform the easing function, defaults to swing
this.pos = jQuery.easing[ options.animatedProperties[this.prop] ]( this.state, n, 0, 1, options.duration );
this.now = this.start + ( (this.end - this.start) * this.pos );
}
// Perform the next step of the animation
this.update();
}
return true;
}
};
jQuery.extend( jQuery.fx, {
tick: function() {
var timer,
timers = jQuery.timers,
i = 0;
for ( ; i < timers.length; i++ ) {
timer = timers[ i ];
// Checks the timer has not already been removed
if ( !timer() && timers[ i ] === timer ) {
timers.splice( i--, 1 );
}
}
if ( !timers.length ) {
jQuery.fx.stop();
}
},
interval: 13,
stop: function() {
clearInterval( timerId );
timerId = null;
},
speeds: {
slow: 600,
fast: 200,
// Default speed
_default: 400
},
step: {
opacity: function( fx ) {
jQuery.style( fx.elem, "opacity", fx.now );
},
_default: function( fx ) {
if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
fx.elem.style[ fx.prop ] = fx.now + fx.unit;
} else {
fx.elem[ fx.prop ] = fx.now;
}
}
}
});
// Ensure props that can't be negative don't go there on undershoot easing
jQuery.each( fxAttrs.concat.apply( [], fxAttrs ), function( i, prop ) {
// exclude marginTop, marginLeft, marginBottom and marginRight from this list
if ( prop.indexOf( "margin" ) ) {
jQuery.fx.step[ prop ] = function( fx ) {
jQuery.style( fx.elem, prop, Math.max(0, fx.now) + fx.unit );
};
}
});
if ( jQuery.expr && jQuery.expr.filters ) {
jQuery.expr.filters.animated = function( elem ) {
return jQuery.grep(jQuery.timers, function( fn ) {
return elem === fn.elem;
}).length;
};
}
// Try to restore the default display value of an element
function defaultDisplay( nodeName ) {
if ( !elemdisplay[ nodeName ] ) {
var body = document.body,
elem = jQuery( "<" + nodeName + ">" ).appendTo( body ),
display = elem.css( "display" );
elem.remove();
// If the simple way fails,
// get element's real default display by attaching it to a temp iframe
if ( display === "none" || display === "" ) {
// No iframe to use yet, so create it
if ( !iframe ) {
iframe = document.createElement( "iframe" );
iframe.frameBorder = iframe.width = iframe.height = 0;
}
body.appendChild( iframe );
// Create a cacheable copy of the iframe document on first call.
// IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML
// document to it; WebKit & Firefox won't allow reusing the iframe document.
if ( !iframeDoc || !iframe.createElement ) {
iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
iframeDoc.write( ( jQuery.support.boxModel ? "<!doctype html>" : "" ) + "<html><body>" );
iframeDoc.close();
}
elem = iframeDoc.createElement( nodeName );
iframeDoc.body.appendChild( elem );
display = jQuery.css( elem, "display" );
body.removeChild( iframe );
}
// Store the correct default display
elemdisplay[ nodeName ] = display;
}
return elemdisplay[ nodeName ];
}
var getOffset,
rtable = /^t(?:able|d|h)$/i,
rroot = /^(?:body|html)$/i;
if ( "getBoundingClientRect" in document.documentElement ) {
getOffset = function( elem, doc, docElem, box ) {
try {
box = elem.getBoundingClientRect();
} catch(e) {}
// Make sure we're not dealing with a disconnected DOM node
if ( !box || !jQuery.contains( docElem, elem ) ) {
return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
}
var body = doc.body,
win = getWindow( doc ),
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
top = box.top + scrollTop - clientTop,
left = box.left + scrollLeft - clientLeft;
return { top: top, left: left };
};
} else {
getOffset = function( elem, doc, docElem ) {
var computedStyle,
offsetParent = elem.offsetParent,
prevOffsetParent = elem,
body = doc.body,
defaultView = doc.defaultView,
prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
top = elem.offsetTop,
left = elem.offsetLeft;
while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
break;
}
computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
top -= elem.scrollTop;
left -= elem.scrollLeft;
if ( elem === offsetParent ) {
top += elem.offsetTop;
left += elem.offsetLeft;
if ( jQuery.support.doesNotAddBorder && !(jQuery.support.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
top += parseFloat( computedStyle.borderTopWidth ) || 0;
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
}
prevOffsetParent = offsetParent;
offsetParent = elem.offsetParent;
}
if ( jQuery.support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
top += parseFloat( computedStyle.borderTopWidth ) || 0;
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
}
prevComputedStyle = computedStyle;
}
if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
top += body.offsetTop;
left += body.offsetLeft;
}
if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
top += Math.max( docElem.scrollTop, body.scrollTop );
left += Math.max( docElem.scrollLeft, body.scrollLeft );
}
return { top: top, left: left };
};
}
jQuery.fn.offset = function( options ) {
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
var elem = this[0],
doc = elem && elem.ownerDocument;
if ( !doc ) {
return null;
}
if ( elem === doc.body ) {
return jQuery.offset.bodyOffset( elem );
}
return getOffset( elem, doc, doc.documentElement );
};
jQuery.offset = {
bodyOffset: function( body ) {
var top = body.offsetTop,
left = body.offsetLeft;
if ( jQuery.support.doesNotIncludeMarginInBodyOffset ) {
top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
}
return { top: top, left: left };
},
setOffset: function( elem, options, i ) {
var position = jQuery.css( elem, "position" );
// set position first, in-case top/left are set even on static elem
if ( position === "static" ) {
elem.style.position = "relative";
}
var curElem = jQuery( elem ),
curOffset = curElem.offset(),
curCSSTop = jQuery.css( elem, "top" ),
curCSSLeft = jQuery.css( elem, "left" ),
calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
props = {}, curPosition = {}, curTop, curLeft;
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
if ( calculatePosition ) {
curPosition = curElem.position();
curTop = curPosition.top;
curLeft = curPosition.left;
} else {
curTop = parseFloat( curCSSTop ) || 0;
curLeft = parseFloat( curCSSLeft ) || 0;
}
if ( jQuery.isFunction( options ) ) {
options = options.call( elem, i, curOffset );
}
if ( options.top != null ) {
props.top = ( options.top - curOffset.top ) + curTop;
}
if ( options.left != null ) {
props.left = ( options.left - curOffset.left ) + curLeft;
}
if ( "using" in options ) {
options.using.call( elem, props );
} else {
curElem.css( props );
}
}
};
jQuery.fn.extend({
position: function() {
if ( !this[0] ) {
return null;
}
var elem = this[0],
// Get *real* offsetParent
offsetParent = this.offsetParent(),
// Get correct offsets
offset = this.offset(),
parentOffset = rroot.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset();
// Subtract element margins
// note: when an element has margin: auto the offsetLeft and marginLeft
// are the same in Safari causing offset.left to incorrectly be 0
offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0;
offset.left -= parseFloat( jQuery.css(elem, "marginLeft") ) || 0;
// Add offsetParent borders
parentOffset.top += parseFloat( jQuery.css(offsetParent[0], "borderTopWidth") ) || 0;
parentOffset.left += parseFloat( jQuery.css(offsetParent[0], "borderLeftWidth") ) || 0;
// Subtract the two offsets
return {
top: offset.top - parentOffset.top,
left: offset.left - parentOffset.left
};
},
offsetParent: function() {
return this.map(function() {
var offsetParent = this.offsetParent || document.body;
while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
offsetParent = offsetParent.offsetParent;
}
return offsetParent;
});
}
});
// Create scrollLeft and scrollTop methods
jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) {
var top = /Y/.test( prop );
jQuery.fn[ method ] = function( val ) {
return jQuery.access( this, function( elem, method, val ) {
var win = getWindow( elem );
if ( val === undefined ) {
return win ? (prop in win) ? win[ prop ] :
jQuery.support.boxModel && win.document.documentElement[ method ] ||
win.document.body[ method ] :
elem[ method ];
}
if ( win ) {
win.scrollTo(
!top ? val : jQuery( win ).scrollLeft(),
top ? val : jQuery( win ).scrollTop()
);
} else {
elem[ method ] = val;
}
}, method, val, arguments.length, null );
};
});
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :
false;
}
// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
var clientProp = "client" + name,
scrollProp = "scroll" + name,
offsetProp = "offset" + name;
// innerHeight and innerWidth
jQuery.fn[ "inner" + name ] = function() {
var elem = this[0];
return elem ?
elem.style ?
parseFloat( jQuery.css( elem, type, "padding" ) ) :
this[ type ]() :
null;
};
// outerHeight and outerWidth
jQuery.fn[ "outer" + name ] = function( margin ) {
var elem = this[0];
return elem ?
elem.style ?
parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
this[ type ]() :
null;
};
jQuery.fn[ type ] = function( value ) {
return jQuery.access( this, function( elem, type, value ) {
var doc, docElemProp, orig, ret;
if ( jQuery.isWindow( elem ) ) {
// 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
doc = elem.document;
docElemProp = doc.documentElement[ clientProp ];
return jQuery.support.boxModel && docElemProp ||
doc.body && doc.body[ clientProp ] || docElemProp;
}
// Get document width or height
if ( elem.nodeType === 9 ) {
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
doc = elem.documentElement;
// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
// instead we use the correct client[Width/Height]
// support:IE6
if ( doc[ clientProp ] >= doc[ scrollProp ] ) {
return doc[ clientProp ];
}
return Math.max(
elem.body[ scrollProp ], doc[ scrollProp ],
elem.body[ offsetProp ], doc[ offsetProp ]
);
}
// Get width or height on the element
if ( value === undefined ) {
orig = jQuery.css( elem, type );
ret = parseFloat( orig );
return jQuery.isNumeric( ret ) ? ret : orig;
}
// Set the width or height on the element
jQuery( elem ).css( type, value );
}, type, value, arguments.length, null );
};
});
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
// Expose jQuery as an AMD module, but only for AMD loaders that
// understand the issues with loading multiple versions of jQuery
// in a page that all might call define(). The loader will indicate
// they have special allowances for multiple jQuery versions by
// specifying define.amd.jQuery = true. Register as a named module,
// since jQuery can be concatenated with other files that may use define,
// but not use a proper concatenation script that understands anonymous
// AMD modules. A named AMD is safest and most robust way to register.
// Lowercase jquery is used because AMD module names are derived from
// file names, and jQuery is normally delivered in a lowercase file name.
// Do this after creating the global so that if an AMD module wants to call
// noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
})( window );
/**
* jQuery hashchange 1.0.0
*
* (based on jquery.history)
*
* Copyright (c) 2008 Chris Leishman (chrisleishman.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*/
(function($) {
$.fn.extend({
hashchange: function(callback) { this.bind('hashchange', callback) },
openOnClick: function(href) {
if (href === undefined || href.length == 0)
href = '#';
return this.click(function(ev) {
if (href && href.charAt(0) == '#') {
// execute load in separate call stack
window.setTimeout(function() { $.locationHash(href) }, 0);
} else {
window.location(href);
}
ev.stopPropagation();
return false;
});
}
});
// IE 8 introduces the hashchange event natively - so nothing more to do
if ($.browser.msie && document.documentMode && document.documentMode >= 8) {
$.extend({
locationHash: function(hash) {
if (!hash) hash = '#';
else if (hash.charAt(0) != '#') hash = '#' + hash;
location.hash = hash;
}
});
return;
}
var curHash;
// hidden iframe for IE (earlier than 8)
var iframe;
$.extend({
locationHash: function(hash) {
if (curHash === undefined) return;
if (!hash) hash = '#';
else if (hash.charAt(0) != '#') hash = '#' + hash;
location.hash = hash;
if (curHash == hash) return;
curHash = hash;
if ($.browser.msie) updateIEFrame(hash);
$.event.trigger('hashchange');
}
});
$(document).ready(function() {
curHash = location.hash;
if ($.browser.msie) {
// stop the callback firing twice during init if no hash present
if (curHash == '') curHash = '#';
// add hidden iframe for IE
iframe = $('<iframe />').hide().get(0);
$('body').prepend(iframe);
updateIEFrame(location.hash);
setInterval(checkHashIE, 100);
} else {
setInterval(checkHash, 100);
}
});
$(window).unload(function() { iframe = null });
function checkHash() {
var hash = location.hash;
if (hash != curHash) {
curHash = hash;
$.event.trigger('hashchange');
}
}
if ($.browser.msie) {
// Attach a live handler for any anchor links
$('a[href^=#]').live('click', function() {
var hash = $(this).attr('href');
// Don't intercept the click if there is an existing anchor on the page
// that matches this hash
if ($(hash).length == 0 && $('a[name='+hash.slice(1)+']').length == 0) {
$.locationHash(hash);
return false;
}
});
}
function checkHashIE() {
// On IE, check for location.hash of iframe
var idoc = iframe.contentDocument || iframe.contentWindow.document;
var hash = idoc.location.hash;
if (hash == '') hash = '#';
if (hash != curHash) {
if (location.hash != hash) location.hash = hash;
curHash = hash;
$.event.trigger('hashchange');
}
}
function updateIEFrame(hash) {
if (hash == '#') hash = '';
var idoc = iframe.contentWindow.document;
idoc.open();
idoc.close();
if (idoc.location.hash != hash) idoc.location.hash = hash;
}
})(jQuery);
// IE...
if (!Date.now) {
Date.now = function() {
return new Date().getTime();
}
}
var Mizuho = {
/** Cached DOM elements so that we don't have to re-find them over and over. */
$document: undefined,
$window: undefined,
$mainSections: undefined,
$sectionHeaders: undefined,
/** Constants */
MAX_TOC_LEVEL: 3,
sectionHeadersSelector: undefined,
scrollMemory: {},
changingHash: false,
activeHash: undefined,
/** Whether in single-page or multi-page mode. Either 'single' or 'multi'. */
mode: 'single',
/** Whether smooth scrolling is enabled. It is always enabled except right
* after page load: when the page is scrolled to the section as pointed to
* by location.hash.
*/
smoothScrolling: true,
initialize: function() {
this.sectionHeadersSelector = '';
for (var i = 0; i < this.MAX_TOC_LEVEL; i++) {
if (i != 0) {
this.sectionHeadersSelector += ', ';
}
this.sectionHeadersSelector += 'h' + (i + 2);
}
this.$document = $(document);
this.$window = $(window);
this.$mainSections = $('.sect1');
this.$sectionHeaders = $(this.sectionHeadersSelector, '#content');
this.$sectionHeaders.sort(function(a, b) {
var off_a = $(a).offset();
var off_b = $(b).offset();
return off_a.top - off_b.top;
});
if (this.isMobileDevice()) {
$(document.body).addClass('mobile');
}
},
/********* Generic utility functions *********/
isMobileDevice: function() {
return navigator.userAgent.match(
/(IEMobile|Windows CE|NetFront|PlayStation|PLAYSTATION|like Mac OS X|MIDP|UP\.Browser|Symbian|Nintendo|Android)/
);
},
virtualAnimate: function(options) {
var options = $.extend({
duration: 1000
}, options || {});
var animation_start = Date.now();
var animation_end = Date.now() + options.duration;
var interval = animation_end - animation_start;
this._virtualAnimate_step(animation_start, animation_end, interval, options);
},
_virtualAnimate_step: function(animation_start, animation_end, interval, options) {
var self = this;
var now = new Date();
var progress = (now - animation_start) / interval;
if (progress > 1) {
progress = 1;
}
progress = (1 + Math.sin(-Math.PI / 2 + progress * Math.PI)) / 2;
options.step(progress);
if (now < animation_end) {
setTimeout(function() {
self._virtualAnimate_step(animation_start,
animation_end, interval, options);
}, 15);
} else {
options.step(1);
if (options.finish) {
options.finish();
}
}
},
smoothlyScrollTo: function(top) {
if (!this.smoothScrolling) {
return this.setScrollTop(top);
}
var self = this;
var $document = this.$document;
var current = $document.scrollTop();
this.virtualAnimate({
duration: 300,
step: function(x) {
$document.scrollTop(Math.floor(
top + (1 - x) * (current - top)
));
},
finish: function() {
self.setScrollTop(top);
}
});
},
smoothlyScrollToToc: function() {
this.smoothlyScrollTo($('#toc').position().top);
},
scrollToHeader: function(header) {
this.smoothlyScrollTo($(header).offset().top - 50);
},
setScrollTop: function(top, element) {
// Browsers don't always scroll properly so work around
// this with a few timers.
var self = this;
element = element || this.$document;
element = $(element);
element.scrollTop(top);
setTimeout(function() {
element.scrollTop(top);
}, 1);
setTimeout(function() {
element.scrollTop(top);
self.$document.trigger('mizuho:updateTopBar');
}, 20);
},
/********* Mizuho-specific functions *********/
/** Returns the currently displayed section's header DOM element. */
currentSubsection: function() {
var $sectionHeaders = this.$sectionHeaders;
var scrollTop = this.$document.scrollTop();
var windowHeight = this.$window.height();
var offset;
var low = 0;
var high = this.$sectionHeaders.length - 1;
var mid = 0;
while (low <= high) {
mid = Math.floor((low + high) / 2);
offset = $($sectionHeaders[mid]).offset();
if (offset.top >= scrollTop) {
high = mid - 1;
} else {
low = mid + 1;
}
}
var $found = $($sectionHeaders[low]);
if ($found.offset().top > scrollTop + windowHeight) {
if (low > 0) {
return $sectionHeaders[low - 1];
} else {
return undefined;
}
} else {
return $sectionHeaders[low];
}
},
/** Looks up a section's header DOM element corresponding to a hash name. */
lookupHeader: function(hash) {
var id = hash.replace(/^#!\//, '#');
if (id == '') {
return undefined;
} else {
var header = $(id);
if (header.length == 0) {
return undefined;
} else {
return header;
}
}
}
};
for (var key in Mizuho) {
if (typeof(Mizuho[key]) == 'function') {
Mizuho[key] = $.proxy(Mizuho[key], Mizuho);
}
}
$(document).ready(Mizuho.initialize);
//$(document).ready(Mizuho.installHashbangLinks);
Mizuho.initializeTopBar = $.proxy(function() {
var $window = this.$window;
var $document = this.$document;
var self = this;
var $topbar = $('#topbar');
var $title = $('#header h1');
var $currentSection = $('#current_section');
var isMobileDevice = this.isMobileDevice();
var timerId;
// Create the floating table of contents used in the top bar.
var $floattoc = $('<div id="floattoc"></div>').html($('#toc').html());
$floattoc.find('#toctitle').remove();
$floattoc.find('.comments').remove();
$floattoc.css('visibility', 'hidden');
$floattoc.insertAfter($topbar);
var $floattoclinks = $floattoc.find('a');
$floattoclinks.each(function() {
// Firefox changes '#!' to '#%21' so change that back.
var $this = $(this);
var href = $this.attr('href');
if (href.match(/^#%21/)) {
$this.attr('href', href.replace(/^#%21/, '#!'));
}
});
$floattoclinks.click(function(event) {
self.internalLinkClicked(this, event);
});
// Callback for when the user clicks on the Table of Contents
// button on the top bar.
function showFloatingToc() {
var scrollUpdateTimerId;
function reposition() {
if (isMobileDevice) {
$floattoc.css({
top: $currentSection.offset().top +
$currentSection.innerHeight() +
'px',
height: $window.height() * 0.7 + 'px'
});
}
}
function highlightCurrentTocEntry() {
var currentSubsection = self.currentSubsection();
$floattoclinks.removeClass('current');
if (currentSubsection) {
var currentSubsectionTitle = $(currentSubsection).text();
var $link;
$floattoclinks.each(function() {
if ($(this).text() == currentSubsectionTitle) {
$link = $(this);
return false;
}
});
if ($link) {
$link.addClass('current');
self.setScrollTop(
$floattoc.scrollTop() +
$link.position().top -
$floattoc.height() * 0.45,
$floattoc);
return false;
}
}
}
function hideFloatingToc() {
$currentSection.removeClass('pressed');
$floattoc.css('visibility', 'hidden');
$floattoclinks.unbind('click', hideFloatingToc);
$document.unbind('mousedown', onMouseDown);
$document.unbind('touchdown', onMouseDown);
$document.unbind('mizuho:hideTopBar', hideFloatingToc);
$window.unbind('scroll', onScroll);
if (scrollUpdateTimerId !== undefined) {
clearTimeout(scrollUpdateTimerId);
scrollUpdateTimerId = undefined;
}
}
function onMouseDown(event) {
if (event.target != $floattoc[0]
&& $(event.target).closest('#floattoc').length == 0) {
hideFloatingToc();
}
}
function onScroll(event) {
if (scrollUpdateTimerId === undefined) {
scrollUpdateTimerId = setTimeout(function() {
scrollUpdateTimerId = undefined;
reposition();
highlightCurrentTocEntry();
}, 100);
}
}
// Layout and display floating TOC.
highlightCurrentTocEntry();
var origScrollTop = $document.scrollTop();
var windowWidth = $window.width();
var maxRight = windowWidth - Math.floor(windowWidth * 0.1);
if ($currentSection.offset().left + $floattoc.outerWidth() > maxRight) {
$floattoc.css('left', maxRight - $floattoc.outerWidth());
} else {
$floattoc.css('left', $currentSection.offset().left + 'px');
}
reposition();
$floattoc.css('visibility', 'visible');
$currentSection.addClass('pressed');
$floattoclinks.bind('click', hideFloatingToc);
$document.bind('mousedown', onMouseDown)
$document.bind('touchdown', onMouseDown);
$document.bind('mizuho:hideTopBar', hideFloatingToc);
$window.bind('scroll', onScroll);
}
// Called whenever the user scrolls. Updates the title of the
// Table of Contents button in the top bar to the section that
// the user is currently reading.
function update() {
if ($title.offset().top + $title.height() < $document.scrollTop()) {
if (!$topbar.is(':visible')) {
$topbar.slideDown(250);
$document.trigger('mizuho:showTopBar');
}
} else {
if ($topbar.is(':visible')) {
$topbar.slideUp();
$document.trigger('mizuho:hideTopBar');
}
}
if (isMobileDevice) {
$topbar.css({
top: $document.scrollTop() + 'px',
width: $window.width() -
parseInt($topbar.css('padding-left')) -
parseInt($topbar.css('padding-right')) +
'px'
});
}
var header = self.currentSubsection();
var name;
if (header) {
name = $(header).text();
} else {
name = 'Preamble';
}
$currentSection.text(name);
}
function scheduleUpdate() {
if (timerId !== undefined) {
return;
}
timerId = setTimeout(function() {
timerId = undefined;
update();
}, 100);
}
if (isMobileDevice) {
// Mobile devices don't support position fixed.
$topbar.css('position', 'absolute');
$floattoc.css('position', 'absolute');
}
$currentSection.click(showFloatingToc);
$window.scroll(scheduleUpdate);
$document.bind('mizuho:updateTopBar', update);
}, Mizuho);
$(document).ready(Mizuho.initializeTopBar);
var JUVIA_URL = 'http://juvia.phusion.nl';
var JUVIA_SITE_KEY = '5jpmkyjqlml8rktsfldfpbwth8ig7w9';
var disqus_identifier;
var disqus_title;
var disqus_url;
var disqus_developer = 1;
Mizuho.initializeCommenting = $.proxy(function() {
var self = this;
this.commentBalloons = $('.comments');
this.commentBalloons.click(function() {
self.showCommentsPopup(this);
});
this.reloadCommentCount();
}, Mizuho);
Mizuho.showLightbox = $.proxy(function(creationCallback, closeCallback) {
var lightbox = $(
'<div id="comments_lightbox">' +
' <div id="comments_lightbox_shadow"></div>' +
' <div id="comments_lightbox_contents"><div class="shell"></div></div>' +
'</div>');
var shadow = $('#comments_lightbox_shadow', lightbox);
var contents = $('#comments_lightbox_contents > .shell', lightbox);
function close() {
if (lightbox) {
lightbox.remove();
lightbox = undefined;
if (closeCallback) {
closeCallback();
}
}
}
shadow.click(close);
lightbox.bind('lightbox:close', close);
lightbox.appendTo(document.body);
creationCallback(contents);
}, Mizuho);
Mizuho.getCommentThreadInfo = $.proxy(function(balloon) {
var info = {};
if ($(balloon).closest('#toc').length > 0) {
info.id = 'toctitle';
info.topic = 'toctitle';
info.title = $('#header h1').text() + " - " + $('#toctitle').text();
} else {
var header = $(balloon).next('h2, h3, h4');
if (header.length > 0) {
info.id = header.attr('id');
info.topic = header.data('comment-topic');
info.title = $('#header h1').text() + " - " + header.text();
} else {
info = undefined;
}
}
return info;
}, Mizuho);
Mizuho.callJuviaApi = function(action, options) {
function makeQueryString(options) {
var key, params = [];
for (key in options) {
params.push(
encodeURIComponent(key) +
'=' +
encodeURIComponent(options[key]));
}
return params.join('&');
}
// Makes sure that each call generates a unique URL, otherwise
// the browser may not actually perform the request.
if (!('_juviaRequestCounter' in window)) {
window._juviaRequestCounter = 0;
}
var url =
JUVIA_URL + '/api/' + action +
'?_c=' + window._juviaRequestCounter +
'&' + makeQueryString(options);
window._juviaRequestCounter++;
var s = document.createElement('script');
s.async = true;
s.type = 'text/javascript';
s.className = 'juvia';
s.src = url;
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(s);
}
Mizuho.showCommentsPopup = $.proxy(function(balloon) {
var info = this.getCommentThreadInfo(balloon);
if (!info) {
return;
}
var self = this;
this.showLightbox(function(element) {
// We install a 'Close' button in the Juvia comment form after it has loaded.
function installCloseButton() {
if ($('#comments .juvia-form-actions').size() > 0) {
// The Juvia form is now loaded. Install the button.
var div = $('<div class="juvia-action" style="margin-left: 0.5em"></div>');
var button = $('<input type="button" value="Cancel"></div>').appendTo(div);
div.insertBefore('#comments .juvia-form-actions .juvia-error');
button.click(function() {
$(element).trigger('lightbox:close');
});
} else {
// Continue polling.
setTimeout(installCloseButton, 50);
}
}
setTimeout(installCloseButton, 50);
// Now load the Juvia comments form.
element.html('<div id="comments">Loading comments...</div>');
self.changingHash = true;
location.hash = '#!/' + info.id;
self.callJuviaApi('show_topic.js', {
container : '#comments',
site_key : JUVIA_SITE_KEY,
topic_key : info.topic,
topic_url : location.href,
topic_title : info.topic,
include_base: !window.Juvia,
include_css : !window.Juvia
});
}, function() {
self.reloadCommentCount();
});
}, Mizuho);
Mizuho.reloadCommentCount = $.proxy(function() {
this.callJuviaApi('list_topics.jsonp', {
site_key: JUVIA_SITE_KEY,
jsonp : 'Mizuho.topicListReceived'
});
}, Mizuho);
Mizuho.topicListReceived = $.proxy(function(result) {
var self = this;
var i, topic, map = {};
for (i = 0; i < result.topics.length; i++) {
topic = result.topics[i];
map[topic.key] = topic;
}
this.commentBalloons.each(function() {
var info = self.getCommentThreadInfo(this);
if (info) {
topic = map[info.topic];
if (topic) {
var balloon = $(this);
$('.count', balloon).text(topic.comment_count);
balloon.removeClass('empty');
balloon.addClass('nonempty');
balloon.attr('title', null);
}
}
});
}, Mizuho);
$(document).ready(Mizuho.initializeCommenting);
</script>
</body>
</html>
|