index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Caching</title>
  6. <meta name="author" content="Jonny W">
  7. <!-- Enable responsive viewport -->
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
  10. <!--[if lt IE 9]>
  11. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  12. <![endif]-->
  13. <!-- Le styles -->
  14. <link href="http://jonnnnyw.github.io/php-phantomjs/assets/resources/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  15. <link href="http://jonnnnyw.github.io/php-phantomjs/assets/resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
  16. <link href="http://jonnnnyw.github.io/php-phantomjs/assets/resources/syntax/syntax.css" rel="stylesheet">
  17. <link href="http://jonnnnyw.github.io/php-phantomjs/assets/css/style.css" rel="stylesheet">
  18. <!-- Le fav and touch icons -->
  19. <!-- Update these with your own images
  20. <link rel="shortcut icon" href="images/favicon.ico">
  21. <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
  22. <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
  23. <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
  24. -->
  25. <link rel="alternate" type="application/rss+xml" title="" href="http://jonnnnyw.github.io/php-phantomjs/feed.xml">
  26. <script>
  27. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  28. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  29. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  30. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  31. ga('create', 'UA-53289013-1', 'auto');
  32. ga('send', 'pageview');
  33. </script>
  34. </head>
  35. <body>
  36. <nav class="navbar navbar-default visible-xs" role="navigation" id="global-nav">
  37. <!-- Brand and toggle get grouped for better mobile display -->
  38. <div class="navbar-header">
  39. <button type="button" class="navbar-toggle" data-parent="#global-nav" data-toggle="collapse" data-target="#navbar-collapse-main">
  40. <span class="sr-only">Toggle navigation</span>
  41. <span class="icon-bar"></span>
  42. <span class="icon-bar"></span>
  43. <span class="icon-bar"></span>
  44. </button>
  45. <button type="button" class="navbar-toggle version-toggle" data-parent="#global-nav" data-toggle="collapse" data-target="#navbar-collapse-version">
  46. <span class="sr-only">Toggle navigation</span>
  47. <span class="fa fa-terminal"><b>4.0</b> version</</span>
  48. </button>
  49. <a class="navbar-brand" href="http://jonnnnyw.github.io/php-phantomjs/">
  50. <img src="http://jonnnnyw.github.io/php-phantomjs/assets/media/phantomjs-small.png" class="img-circle" />
  51. PHP PhantomJs
  52. </a>
  53. </div>
  54. <div class="panel">
  55. <!-- Collect the nav links, forms, and other content for toggling -->
  56. <div class="collapse navbar-collapse" id="navbar-collapse-version">
  57. <ul class="nav navbar-nav">
  58. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/" title="Version 4.0" class="active"><b>4.0</b> version</a></li>
  59. <li><a href="http://jonnnnyw.github.io/php-phantomjs/3.0/" title="Version 3.0"><b>3.0</b> version</a></li>
  60. </ul>
  61. </div><!-- /.navbar-collapse -->
  62. </div>
  63. <div class="panel">
  64. <!-- Collect the nav links, forms, and other content for toggling -->
  65. <div class="collapse navbar-collapse" id="navbar-collapse-main">
  66. <ul class="nav navbar-nav">
  67. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/">Introduction</a></li>
  68. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/2-installation/">Installation</a></li>
  69. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/">Usage</a></li>
  70. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/4-custom-scripts/">Custom Scripts</a></li>
  71. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/5-caching/">Caching</a></li>
  72. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/6-debugging/">Debugging</a></li>
  73. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/7-troubleshooting/">Troubleshooting</a></li>
  74. </ul>
  75. </div><!-- /.navbar-collapse -->
  76. </div>
  77. </nav>
  78. <!-- version-menu-dropdown -->
  79. <div class="btn-group hidden-xs" id="nav-version">
  80. <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
  81. <i class="fa fa-terminal"><b>4.0</b> version</i>
  82. </button>
  83. <ul class="dropdown-menu" role="menu">
  84. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/" title="4.0 version" class="active"><b>4.0</b> version</a></li>
  85. <li><a href="http://jonnnnyw.github.io/php-phantomjs/3.0/" title="3.0 version"><b>3.0</b> version</a></li>
  86. <li class="divider"></li>
  87. </ul>
  88. </div>
  89. <!-- nav-menu-dropdown -->
  90. <div class="btn-group hidden-xs" id="nav-menu">
  91. <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
  92. <i class="fa fa-bars"></i>
  93. </button>
  94. <ul class="dropdown-menu" role="menu">
  95. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/"><i class="fa fa-folder"></i>Introduction</a></li>
  96. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/2-installation/"><i class="fa fa-folder"></i>Installation</a></li>
  97. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/"><i class="fa fa-folder"></i>Usage</a></li>
  98. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/4-custom-scripts/"><i class="fa fa-folder"></i>Custom Scripts</a></li>
  99. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/5-caching/"><i class="fa fa-folder"></i>Caching</a></li>
  100. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/6-debugging/"><i class="fa fa-folder"></i>Debugging</a></li>
  101. <li><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/7-troubleshooting/"><i class="fa fa-folder"></i>Troubleshooting</a></li>
  102. <li class="divider"></li>
  103. <li><a href="#"><i class="fa fa-arrow-up"></i>Top of Page</a></li>
  104. </ul>
  105. </div>
  106. <div class="col-sm-3 sidebar hidden-xs">
  107. <! -- sidebar.html -->
  108. <header class="sidebar-header" role="banner">
  109. <a href="http://jonnnnyw.github.io/php-phantomjs/">
  110. <img src="http://jonnnnyw.github.io/php-phantomjs/assets/media/phantomjs.png" class="img-circle" />
  111. </a>
  112. <h3 class="title">
  113. <a href="http://jonnnnyw.github.io/php-phantomjs/">PHP PhantomJs</a>
  114. </h3>
  115. </header>
  116. <div id="bio" class="text-center">
  117. Run PhantomJS scripts through PHP
  118. </div>
  119. <div id="contact-list" class="text-center">
  120. <ul class="list-unstyled list-inline">
  121. <li>
  122. <iframe src="http://ghbtns.com/github-btn.html?user=jonnnnyw&repo=php-phantomjs&type=watch&count=true"
  123. allowtransparency="true" frameborder="0" scrolling="0" width="85" height="20"></iframe>
  124. </li>
  125. <li>
  126. <iframe src="http://ghbtns.com/github-btn.html?user=jonnnnyw&repo=php-phantomjs&type=fork&count=true"
  127. allowtransparency="true" frameborder="0" scrolling="0" width="83" height="20"></iframe>
  128. </li>
  129. </ul>
  130. </div>
  131. <! -- sidebar.html end -->
  132. </div>
  133. <p id="version-notice">You are currently viewing version <span>4.0</span> documentation.</p>
  134. <div class="col-sm-9 col-sm-offset-3">
  135. <div class="page-header">
  136. <h1>Caching </h1>
  137. </div>
  138. <article>
  139. <div class="col-sm-10">
  140. <div class="article_body">
  141. <ul>
  142. <li><a href="#script-caching">Script caching</a></li>
  143. <li><a href="#clearing-the-cache">Clearing the cache</a></li>
  144. <li><a href="#disabling-the-cache">Disabling the cache</a></li>
  145. </ul>
  146. <hr />
  147. <h2 id="script-caching">Script caching</h2>
  148. <p>By default the PHP PhantomJs library compiles and aggressively caches script templates the first time that they are run. This means that if you override any <a href="http://jonnnnyw.github.io/php-phantomjs/4.0/custom-scripts/">partial scripts</a> after the script template has been cached by the library then the changes will not take affect until you <a href="#clearing-the-cache">clear the compiled cache</a>.</p>
  149. <p>It is recommended that you <a href="#disabling-the-cache">disable the compiler cache</a> while developing your own custom scripts.</p>
  150. <blockquote>
  151. <h4 id="note">Note</h4>
  152. <p>The default cache location is the system tmp directory. The location of this directory can be found through the <code>sys_get_temp_dir()</code> PHP directive.</p>
  153. </blockquote>
  154. <h2 id="disabling-the-cache">Disabling the cache</h2>
  155. <p>The compiler cache can be easily disabled. When disabled script templates will be compiled for each request and no caching will take place.</p>
  156. <figure class="highlight"><pre><code class="language-php" data-lang="php"><span class="x"> </span>
  157. <span class="x"> </span><span class="cp">&lt;?php</span>
  158. <span class="k">use</span> <span class="nx">JonnyW\PhantomJs\Client</span><span class="p">;</span>
  159. <span class="nv">$client</span> <span class="o">=</span> <span class="nx">Client</span><span class="o">::</span><span class="na">getInstance</span><span class="p">();</span>
  160. <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getProcedureCompiler</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">disableCache</span><span class="p">();</span></code></pre></figure>
  161. <p>The compiler cache is enabled by default however you can enable it manually if the situation arises.</p>
  162. <figure class="highlight"><pre><code class="language-php" data-lang="php"><span class="x"> </span>
  163. <span class="x"> </span><span class="cp">&lt;?php</span>
  164. <span class="k">use</span> <span class="nx">JonnyW\PhantomJs\Client</span><span class="p">;</span>
  165. <span class="nv">$client</span> <span class="o">=</span> <span class="nx">Client</span><span class="o">::</span><span class="na">getInstance</span><span class="p">();</span>
  166. <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getProcedureCompiler</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">enableCache</span><span class="p">();</span></code></pre></figure>
  167. <blockquote>
  168. <h4 id="important">Important</h4>
  169. <p>Script caching greatly improves performance therefore you should ensure that the cache is enabled in any production environment or in situtations where performance is important.</p>
  170. </blockquote>
  171. <h2 id="clearing-the-cache">Clearing the cache</h2>
  172. <p>The compiler cache can be easily cleared. This will force script templates to be recompiled and cached on the next request.</p>
  173. <figure class="highlight"><pre><code class="language-php" data-lang="php"><span class="x"> </span>
  174. <span class="x"> </span><span class="cp">&lt;?php</span>
  175. <span class="k">use</span> <span class="nx">JonnyW\PhantomJs\Client</span><span class="p">;</span>
  176. <span class="nv">$client</span> <span class="o">=</span> <span class="nx">Client</span><span class="o">::</span><span class="na">getInstance</span><span class="p">();</span>
  177. <span class="nv">$client</span><span class="o">-&gt;</span><span class="na">getProcedureCompiler</span><span class="p">()</span><span class="o">-&gt;</span><span class="na">clearCache</span><span class="p">();</span></code></pre></figure>
  178. </div>
  179. </div>
  180. <div class="clearfix"></div>
  181. <hr>
  182. <ul class="pager">
  183. <li class="previous"><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/6-debugging/" title="Debugging">&larr; Debugging</a></li>
  184. <li class="next"><a href="http://jonnnnyw.github.io/php-phantomjs/4.0/4-custom-scripts/" title="Custom Scripts">Custom Scripts &rarr;</a></li>
  185. </ul>
  186. </article>
  187. <footer>
  188. <hr/>
  189. <p>
  190. &copy; 2016 PHP PhantomJs
  191. </p>
  192. </footer>
  193. </div>
  194. <script type="text/javascript" src="http://jonnnnyw.github.io/php-phantomjs/assets/resources/jquery/jquery.min.js"></script>
  195. <script type="text/javascript" src="http://jonnnnyw.github.io/php-phantomjs/assets/resources/bootstrap/js/bootstrap.min.js"></script>
  196. <script type="text/javascript" src="http://jonnnnyw.github.io/php-phantomjs/assets/js/app.js"></script>
  197. </body>
  198. </html>