├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── README.zh.md ├── bin ├── crontab.php └── php_crontab ├── composer.json ├── example ├── daemon.php ├── http_daemon.php ├── simple.php └── task_loader.php ├── phpunit.xml ├── src └── Jenner │ └── Crontab │ ├── AbstractDaemon.php │ ├── Crontab.php │ ├── Daemon.php │ ├── HTTP │ └── Server.php │ ├── HttpDaemon.php │ ├── Mission.php │ ├── MissionLoggerFactory.php │ └── Parser │ ├── ConfigParse.php │ ├── CrontabParse.php │ ├── JobParse.php │ └── README.MD └── tests ├── CrontabTest.php ├── CustomHandler.php ├── JobParseTest.php ├── MissionTest.php ├── config.php ├── logger.test.php └── timer.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | .idea/ 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | 8 | services: 9 | - redis-server 10 | 11 | before_script: 12 | - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 13 | - composer self-update 14 | - composer update 15 | 16 | script: 17 | - phpunit --bootstrap vendor/autoload.php tests/ 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -- activemq-xmpp 205 | ========================================================================= 206 | == For the Jabber Software Foundation XSDs == 207 | ========================================================================= 208 | Attribution 2.5 209 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE. 210 | 211 | License 212 | 213 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. 214 | 215 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. 216 | 217 | 1. Definitions 218 | 219 | 1. "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License. 220 | 2. "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License. 221 | 3. "Licensor" means the individual or entity that offers the Work under the terms of this License. 222 | 4. "Original Author" means the individual or entity who created the Work. 223 | 5. "Work" means the copyrightable work of authorship offered under the terms of this License. 224 | 6. "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. 225 | 226 | 2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws. 227 | 228 | 3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below: 229 | 230 | 1. to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works; 231 | 2. to create and reproduce Derivative Works; 232 | 3. to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works; 233 | 4. to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works. 234 | 5. 235 | 236 | For the avoidance of doubt, where the work is a musical composition: 237 | 1. Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work. 238 | 2. Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights agency or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions). 239 | 6. Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions). 240 | 241 | The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved. 242 | 243 | 4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions: 244 | 245 | 1. You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(b), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(b), as requested. 246 | 2. If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit. 247 | 248 | 5. Representations, Warranties and Disclaimer 249 | 250 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. 251 | 252 | 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 253 | 254 | 7. Termination 255 | 256 | 1. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. 257 | 2. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 258 | 259 | 8. Miscellaneous 260 | 261 | 1. Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. 262 | 2. Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License. 263 | 3. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 264 | 4. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. 265 | 5. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. 266 | 267 | Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor. 268 | 269 | Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, neither party will use the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. 270 | 271 | Creative Commons may be contacted at http://creativecommons.org/. 272 | 273 | -- activemq-web 274 | ========================================================================= 275 | == For the behaviour.js library == 276 | ========================================================================= 277 | 278 | Copyright (c) 2005, Ben Nolan 279 | All rights reserved. 280 | 281 | Redistribution and use in source and binary forms, with or without 282 | modification, are permitted provided that the following conditions are 283 | met: 284 | 285 | * Redistributions of source code must retain the above copyright 286 | notice, this list of conditions and the following disclaimer. 287 | * Redistributions in binary form must reproduce the above 288 | copyright notice, this list of conditions and the following 289 | disclaimer in the documentation and/or other materials provided 290 | with the distribution. 291 | * Neither the name of the Ben Nolan nor the names of its 292 | contributors may be used to endorse or promote products derived 293 | from this software without specific prior written permission. 294 | 295 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 296 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 297 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 298 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 299 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 300 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 301 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 302 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 303 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 304 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 305 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 306 | 307 | ========================================================================= 308 | == For the prototype.js library == 309 | ========================================================================= 310 | 311 | Copyright (c) 2005 Sam Stephenson 312 | 313 | Permission is hereby granted, free of charge, to any person obtaining a copy 314 | of this software and associated documentation files (the "Software"), to deal 315 | in the Software without restriction, including without limitation the rights 316 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 317 | copies of the Software, and to permit persons to whom the Software is 318 | furnished to do so, subject to the following conditions: 319 | 320 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 321 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 322 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 323 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 324 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 325 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 326 | SOFTWARE. 327 | 328 | --activemq-web-demo 329 | ========================================================================= 330 | == For the scriptaculous.js library == 331 | ========================================================================= 332 | 333 | // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 334 | // 335 | // Permission is hereby granted, free of charge, to any person obtaining 336 | // a copy of this software and associated documentation files (the 337 | // "Software"), to deal in the Software without restriction, including 338 | // without limitation the rights to use, copy, modify, merge, publish, 339 | // distribute, sublicense, and/or sell copies of the Software, and to 340 | // permit persons to whom the Software is furnished to do so, subject to 341 | // the following conditions: 342 | // 343 | // The above copyright notice and this permission notice shall be 344 | // included in all copies or substantial portions of the Software. 345 | // 346 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 347 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 348 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 349 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 350 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 351 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 352 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 353 | 354 | 355 | ========================================================================= 356 | == For the style.css library == 357 | == For the common.js library == 358 | ========================================================================= 359 | 360 |

License

361 | 362 |

THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

363 | 364 |

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

365 | 366 | 367 |

1. Definitions

368 | 369 |
    370 | 371 |
  1. 372 | "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License. 373 |
  2. 374 | 375 |
  3. 376 | "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  4. 377 | 378 |
  5. 379 | "Licensor" means the individual or entity that offers the Work under the terms of this License. 380 |
  6. 381 | 382 |
  7. 383 | "Original Author" means the individual or entity who created the Work. 384 |
  8. 385 | 386 |
  9. 387 | "Work" means the copyrightable work of authorship offered under the terms of this License. 388 |
  10. 389 | 390 |
  11. 391 | "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. 392 | 393 |
  12. 394 |
395 | 396 |

2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

397 | 398 | 399 |

3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

400 | 401 | 402 |
    403 |
  1. 404 | 405 | to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works; 406 |
  2. 407 | 408 |
  3. 409 | to create and reproduce Derivative Works; 410 |
  4. 411 | 412 |
  5. 413 | to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works; 414 | 415 |
  6. 416 | 417 |
  7. 418 | to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works. 419 |
  8. 420 | 421 |
  9. For the avoidance of doubt, where the work is a musical composition:

    422 | 423 |
      424 |
    1. Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    2. 425 | 426 |
    3. Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights agency or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
  10. 427 | 428 |
  11. Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).
  12. 429 | 430 |
431 | 432 | 433 |

The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

434 | 435 |

4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

436 | 437 | 438 |
    439 |
  1. 440 | You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(b), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(b), as requested. 441 |
  2. 442 | 443 | 444 |
  3. 445 | If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit. 446 |
  4. 447 | 448 |
449 | 450 | 451 | 452 | 453 | 454 | 455 |

5. Representations, Warranties and Disclaimer

456 | 457 |

UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

458 | 459 | 460 |

6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

461 | 462 |

7. Termination

463 | 464 |
    465 | 466 |
  1. 467 | This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. 468 |
  2. 469 | 470 |
  3. 471 | Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 472 |
  4. 473 |
474 | 475 |

8. Miscellaneous

476 | 477 |
    478 | 479 |
  1. 480 | Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. 481 |
  2. 482 | 483 |
  3. 484 | Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License. 485 |
  4. 486 | 487 |
  5. 488 | If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 489 |
  6. 490 | 491 |
  7. 492 | No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. 493 | 494 |
  8. 495 | 496 |
  9. 497 | This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. 498 |
  10. 499 |
500 | 501 | --activemq-web-console 502 | 503 | 504 | ========================================================================= 505 | == For the MochiKit library == 506 | ========================================================================= 507 | 508 | MochiKit is dual-licensed software. It is available under the terms of the 509 | MIT License, or the Academic Free License version 2.1. The full text of 510 | each license is included below. 511 | 512 | MIT License 513 | =========== 514 | 515 | Copyright (c) 2005 Bob Ippolito. All rights reserved. 516 | 517 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 518 | 519 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 520 | 521 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 522 | 523 | 524 | Academic Free License v. 2.1 525 | ============================ 526 | 527 | Copyright (c) 2005 Bob Ippolito. All rights reserved. 528 | 529 | This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work: 530 | 531 | Licensed under the Academic Free License version 2.1 532 | 533 | 1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following: 534 | 535 | a) to reproduce the Original Work in copies; 536 | 537 | b) to prepare derivative works ("Derivative Works") based upon the Original Work; 538 | 539 | c) to distribute copies of the Original Work and Derivative Works to the public; 540 | 541 | d) to perform the Original Work publicly; and 542 | 543 | e) to display the Original Work publicly. 544 | 545 | 2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works. 546 | 547 | 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work. 548 | 549 | 4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license. 550 | 551 | 5) This section intentionally omitted. 552 | 553 | 6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 554 | 555 | 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer. 556 | 557 | 8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. 558 | 559 | 9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions. 560 | 561 | 10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 562 | 563 | 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. � 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License. 564 | 565 | 12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 566 | 567 | 13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 568 | 569 | 14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 570 | 571 | 15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 572 | 573 | This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner. 574 | 575 | ========================================================================= 576 | == For the Plotkit library == 577 | ========================================================================= 578 | 579 | Copyright (c) 2006, Alastair Tse 580 | All rights reserved. 581 | 582 | Redistribution and use in source and binary forms, with or without 583 | modification, are permitted provided that the following conditions are 584 | met: 585 | 586 | * Redistributions of source code must retain the above copyright 587 | notice, this list of conditions and the following disclaimer. 588 | * Redistributions in binary form must reproduce the above 589 | copyright notice, this list of conditions and the following 590 | disclaimer in the documentation and/or other materials provided 591 | with the distribution. 592 | * Neither the name of the Alastair Tse nor the names of its 593 | contributors may be used to endorse or promote products derived 594 | from this software without specific prior written permission. 595 | 596 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 597 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 598 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 599 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 600 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 601 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 602 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 603 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 604 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 605 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 606 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 607 | 608 | ========================================================================= 609 | == For the iecanvas.htc library == 610 | ========================================================================= 611 | 612 | |-----------------------------------------------------------------------------| 613 | | Copyright (c) 2005 Emil A Eklund | 614 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| 615 | | This program is free software; you can redistribute it and/or modify it | 616 | | under the terms of the MIT License. | 617 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| 618 | | Permission is hereby granted, free of charge, to any person obtaining a | 619 | | copy of this software and associated documentation files (the "Software"), | 620 | | to deal in the Software without restriction, including without limitation | 621 | | the rights to use, copy, modify, merge, publish, distribute, sublicense, | 622 | | and/or sell copies of the Software, and to permit persons to whom the | 623 | | Software is furnished to do so, subject to the following conditions: | 624 | | The above copyright notice and this permission notice shall be included in | 625 | | all copies or substantial portions of the Software. | 626 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| 627 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 628 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 629 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 630 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 631 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 632 | | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 633 | | DEALINGS IN THE SOFTWARE. | 634 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -| 635 | 636 | ========================================================================= 637 | == For the standardista-table-sorting.js library == 638 | == For the css.js library == 639 | ========================================================================= 640 | 641 | /** 642 | * Copyright (c) 2006 Neil Crosby 643 | * 644 | * Permission is hereby granted, free of charge, to any person obtaining a copy 645 | * of this software and associated documentation files (the "Software"), to deal 646 | * in the Software without restriction, including without limitation the rights 647 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 648 | * copies of the Software, and to permit persons to whom the Software is 649 | * furnished to do so, subject to the following conditions: 650 | * 651 | * The above copyright notice and this permission notice shall be included in 652 | * all copies or substantial portions of the Software. 653 | * 654 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 655 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 656 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 657 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 658 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 659 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 660 | * SOFTWARE. 661 | **/ 662 | 663 | ========================================================================= 664 | == For the style.css library == 665 | == For the common.js library == 666 | ========================================================================= 667 | 668 |

License

669 | 670 |

THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

671 | 672 |

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

673 | 674 | 675 |

1. Definitions

676 | 677 |
    678 | 679 |
  1. 680 | "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License. 681 |
  2. 682 | 683 |
  3. 684 | "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  4. 685 | 686 |
  5. 687 | "Licensor" means the individual or entity that offers the Work under the terms of this License. 688 |
  6. 689 | 690 |
  7. 691 | "Original Author" means the individual or entity who created the Work. 692 |
  8. 693 | 694 |
  9. 695 | "Work" means the copyrightable work of authorship offered under the terms of this License. 696 |
  10. 697 | 698 |
  11. 699 | "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation. 700 | 701 |
  12. 702 |
703 | 704 |

2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

705 | 706 | 707 |

3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

708 | 709 | 710 |
    711 |
  1. 712 | 713 | to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works; 714 |
  2. 715 | 716 |
  3. 717 | to create and reproduce Derivative Works; 718 |
  4. 719 | 720 |
  5. 721 | to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works; 722 | 723 |
  6. 724 | 725 |
  7. 726 | to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works. 727 |
  8. 728 | 729 |
  9. For the avoidance of doubt, where the work is a musical composition:

    730 | 731 |
      732 |
    1. Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    2. 733 | 734 |
    3. Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights agency or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
  10. 735 | 736 |
  11. Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).
  12. 737 | 738 |
739 | 740 | 741 |

The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

742 | 743 |

4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

744 | 745 | 746 |
    747 |
  1. 748 | You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(b), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(b), as requested. 749 |
  2. 750 | 751 | 752 |
  3. 753 | If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit. 754 |
  4. 755 | 756 |
757 | 758 | 759 | 760 | 761 | 762 | 763 |

5. Representations, Warranties and Disclaimer

764 | 765 |

UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

766 | 767 | 768 |

6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

769 | 770 |

7. Termination

771 | 772 |
    773 | 774 |
  1. 775 | This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License. 776 |
  2. 777 | 778 |
  3. 779 | Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above. 780 |
  4. 781 |
782 | 783 |

8. Miscellaneous

784 | 785 |
    786 | 787 |
  1. 788 | Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License. 789 |
  2. 790 | 791 |
  3. 792 | Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License. 793 |
  4. 794 | 795 |
  5. 796 | If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. 797 |
  6. 798 | 799 |
  7. 800 | No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent. 801 | 802 |
  8. 803 | 804 |
  9. 805 | This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You. 806 |
  10. 807 |
808 | 103.245.222.133 809 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | php_crontab 2 | ============= 3 | [![Latest Stable Version](https://poser.pugx.org/jenner/crontab/v/stable)](https://packagist.org/packages/jenner/crontab) 4 | [![Total Downloads](https://poser.pugx.org/jenner/crontab/downloads)](https://packagist.org/packages/jenner/crontab) 5 | [![Latest Unstable Version](https://poser.pugx.org/jenner/crontab/v/unstable)](https://packagist.org/packages/jenner/crontab) 6 | [![License](https://poser.pugx.org/jenner/crontab/license)](https://packagist.org/packages/jenner/crontab) 7 | [![License](https://travis-ci.org/huyanping/php_crontab.svg)](https://travis-ci.org/huyanping/php_crontab.svgb) 8 | 9 | php crontab base on pcntl and react/event-loop 10 | 11 | [中文说明](https://github.com/huyanping/php_crontab/blob/master/README.zh.md "中文说明") 12 | 13 | Why use php_crontab? 14 | ------------ 15 | When we have a handful of crontab tasks, crontab service is enough for us to manage them. 16 | If we have many crontab tasks, there will be some problems like: 17 | + The crontab tasks are managed in a text file. If there are no comment, it will be 18 | hard for fresh man to understand what they are. 19 | + If the crontab tasks are distributed in different servers, it will be hard to manage them. 20 | + If you want to collect the crontab tasks' logs, it will be not easy. 21 | + Tasks of different users must written in different files. 22 | Based on the above reasons, we need a crontab manager which can manage crontab tasks together and configure the tasks. 23 | 24 | How to use php_crontab? 25 | --------------- 26 | First `composer require jenner/crontab`. 27 | There are two ways to use php_crontab to manage your crontab tasks. 28 | You can just write a php script and add it to the crontab config file 29 | with the command `crontab -e`. The php script should run every minute. For example `tests/simple.php` 30 | Or you can write a php daemon script which will run as a service and will not exit until someone kill it. 31 | It will check the tasks every minute. For example `tests/daemon.php` 32 | 33 | Import 34 | ------------------ 35 | ```shell 36 | composer require jenner/crontab 37 | ``` 38 | 39 | Properties 40 | ----------- 41 | + The crontab tasks can be stored in any way you what. For example, mysql, reids. 42 | What's more? You can develop a web application to manage them. 43 | + The tasks of different users can be managed together. 44 | + Multi-Process, every task is a process. 45 | + You can set the user and group of a crontab task 46 | + STDOUT can be redirected 47 | + Based on react/event-loop, it can run as a daemon. 48 | + A HTTP server which you can manage the crontab tasks through it. 49 | + Dynamic task loader, you can register a task loader by Daemon::registerTaskLoader, 50 | which will execute every 60 seconds and update the crontab tasks. 51 | 52 | HTTP interfaces 53 | ------------- 54 | HTTP METHOD: `GET` 55 | + `add` add new task to crontab server 56 | + `get_by_name` get task by name 57 | + `remove_by_name` remove task by name 58 | + `clear` clear all task 59 | + `get` get all tasks 60 | + `start` start crontab loop 61 | + `stop` stop crontab loop 62 | 63 | Examples: 64 | ```shell 65 | http://host:port/add?name=name&cmd=cmd&time=time&out=out&user=user&group=group&comment=comment 66 | http://host:port/get_by_name?name=name 67 | http://host:port/remove_by_name?name=name 68 | http://host:port/clear 69 | http://host:port/get 70 | http://host:port/start 71 | http://host:port/stop 72 | ``` 73 | 74 | TODO 75 | ------------------ 76 | + add log handler interface. 77 | + add http log handler, socket log handler, file handler and so on. 78 | + separate stdout and stderr. use different handlers 79 | 80 | 81 | **run based on crontab service** 82 | ```shell 83 | * * * * * php demo.php 84 | ``` 85 | ```php 86 | 'ls', 90 | 'cmd' => "ls -al", 91 | 'out' => '/tmp/php_crontab.log', 92 | 'err' => '/tmp/php_crontab.log', 93 | 'time' => '* * * * *', 94 | 'user' => 'www', 95 | 'group' => 'www' 96 | ], 97 | [ 98 | 'name' => 'ls', 99 | 'cmd' => "ls -al", 100 | 'out' => '/tmp/php_crontab.log', 101 | 'err' => '/tmp/php_crontab.log', 102 | 'time' => '* * * * *', 103 | 'user' => 'www', 104 | 'group' => 'www' 105 | ], 106 | ]; 107 | 108 | $tasks = array(); 109 | foreach($missions as $mission){ 110 | $tasks[] = new \Jenner\Crontab\Mission($mission['name'], $mission['cmd'], $mission['time'], $mission['out']); 111 | } 112 | 113 | $crontab_server = new \Jenner\Crontab\Crontab(null, $tasks); 114 | $crontab_server->start(time()); 115 | ``` 116 | **run as a daemon** 117 | 118 | it will check the task configs every minute. 119 | ```php 120 | $missions = [ 121 | [ 122 | 'name' => 'ls', 123 | 'cmd' => "ls -al", 124 | 'out' => '/tmp/php_crontab.log', 125 | 'err' => '/tmp/php_crontab.log', 126 | 'time' => '* * * * *', 127 | 'user' => 'www', 128 | 'group' => 'www' 129 | ], 130 | [ 131 | 'name' => 'ls', 132 | 'cmd' => "ls -al", 133 | 'out' => '/tmp/php_crontab.log', 134 | 'err' => '/tmp/php_crontab.log', 135 | 'time' => '* * * * *', 136 | 'user' => 'www', 137 | 'group' => 'www' 138 | ], 139 | ]; 140 | 141 | $daemon = new \Jenner\Crontab\Daemon($missions); 142 | $daemon->start(); 143 | ``` 144 | Or use the task loader 145 | ```php 146 | function task_loader() { 147 | $missions = [ 148 | [ 149 | 'name' => 'ls', 150 | 'cmd' => "ls -al", 151 | 'out' => '/tmp/php_crontab.log', 152 | 'time' => '* * * * *', 153 | 'user' => 'www', 154 | 'group' => 'www' 155 | ], 156 | [ 157 | 'name' => 'ls', 158 | 'cmd' => "ls -al", 159 | 'out' => '/tmp/php_crontab.log', 160 | 'time' => '* * * * *', 161 | 'user' => 'www', 162 | 'group' => 'www' 163 | ], 164 | ]; 165 | 166 | return $missions; 167 | } 168 | 169 | $daemon = new \Jenner\Crontab\Daemon(); 170 | $daemon->registerTaskLoader("task_loader"); 171 | $daemon->start(); 172 | ``` 173 | 174 | **run as a daemon and start the http server** 175 | ```php 176 | $missions = [ 177 | [ 178 | 'name' => 'ls', 179 | 'cmd' => "ls -al", 180 | 'out' => '/tmp/php_crontab.log', 181 | 'err' => '/tmp/php_crontab.log', 182 | 'time' => '* * * * *', 183 | 'user' => 'www', 184 | 'group' => 'www' 185 | ], 186 | [ 187 | 'name' => 'ls', 188 | 'cmd' => "ls -al", 189 | 'out' => '/tmp/php_crontab.log', 190 | 'err' => '/tmp/php_crontab.log', 191 | 'time' => '* * * * *', 192 | 'user' => 'www', 193 | 'group' => 'www' 194 | ], 195 | ]; 196 | 197 | $http_daemon = new \Jenner\Crontab\HttpDaemon($missions, "php_crontab.log"); 198 | $http_daemon->start($port = 6364); 199 | ``` 200 | Then you can manage the crontab task by curl like: 201 | ```shell 202 | curl http://127.0.0.1:6364/get_by_name?name=ls 203 | curl http://127.0.0.1:6364/remove_by_name?name=hostname 204 | curl http://127.0.0.1:6364/get 205 | ``` 206 | 207 | **run the script** 208 | ```shell 209 | [root@jenner php_crontab]# ./bin/php_crontab 210 | php_crontab help: 211 | -c --config crontab tasks config file 212 | -p --port http server port 213 | -f --pid-file daemon pid file 214 | -l --log crontab log file 215 | [root@jenner php_crontab]#nohup ./bin/php_crontab -c xxoo.php -p 8080 -f /var/php_crontab.pid -l /var/logs/php_crontab.log >/dev/null & 216 | ``` 217 | 218 | [blog:www.huyanping.cn](http://www.huyanping.cn/ "程序猿始终不够") 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /README.zh.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/white-poto/php_crontab/6b636727aa9ec4afb6e143356d08fa29f3050fdd/README.zh.md -------------------------------------------------------------------------------- /bin/crontab.php: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | start(); 15 | } catch (Exception $e) { 16 | $crontab->keepPidFile(); 17 | echo "Exception:" . $e->getMessage() . PHP_EOL; 18 | echo $e->getTraceAsString() . PHP_EOL; 19 | } 20 | 21 | 22 | class Crontab 23 | { 24 | 25 | /** 26 | * @var \Jenner\Crontab\AbstractDaemon 27 | */ 28 | protected $daemon; 29 | /** 30 | * @var array 31 | */ 32 | protected $params; 33 | 34 | /** 35 | * @var string crontab missions config file 36 | */ 37 | protected $config_file; 38 | 39 | /** 40 | * @var int http server port 41 | */ 42 | protected $port; 43 | 44 | /** 45 | * @var string pid file 46 | */ 47 | protected $pid_file = './php_crontab.pid'; 48 | 49 | /** 50 | * @var string crontab log 51 | */ 52 | protected $log; 53 | 54 | /** 55 | * @var array missions 56 | */ 57 | protected $missions; 58 | 59 | /** 60 | * @var bool delete pid file or not 61 | */ 62 | protected $keep_pid_file = false; 63 | 64 | /** 65 | * @var array console args 66 | */ 67 | protected $args = array( 68 | 'help' => 'h', 69 | 'config:' => 'c:', 70 | 'port:' => 'p:', 71 | 'pid-file:' => 'f:', 72 | 'log:' => 'l:', 73 | ); 74 | 75 | /** 76 | * 77 | */ 78 | protected function help() 79 | { 80 | echo <<init(); 97 | $this->checkPidFile(); 98 | $this->daemon = $this->factory(); 99 | $this->daemon->start(); 100 | } 101 | 102 | /** 103 | * @return bool 104 | */ 105 | protected function checkPidFile() 106 | { 107 | register_shutdown_function(array($this, 'deletePidFile')); 108 | 109 | if (file_exists($this->pid_file)) { 110 | if (!is_readable($this->pid_file) || !is_writable($this->pid_file)) { 111 | throw new RuntimeException("the pid file is not readable or writable"); 112 | } 113 | $pid = file_get_contents($this->pid_file); 114 | if ($pid != getmypid()) { 115 | $message = "the pid file is exists. " . 116 | "so maybe the crontab is already running. PID:" . $pid . 117 | ". pid file:" . $this->pid_file . PHP_EOL; 118 | throw new RuntimeException($message); 119 | } 120 | } else { 121 | $touch = touch($this->pid_file); 122 | if (!$touch) { 123 | throw new RuntimeException("create pid file failed"); 124 | } 125 | } 126 | 127 | $put = file_put_contents($this->pid_file, getmypid()); 128 | if (!$put) { 129 | throw new RuntimeException("write pid file failed"); 130 | } 131 | 132 | return true; 133 | } 134 | 135 | /** 136 | * @throws Exception 137 | */ 138 | protected function init() 139 | { 140 | $this->params = getopt(implode('', array_values($this->args)), array_keys($this->args)); 141 | 142 | if ($this->argExists('help') || empty($this->params)) { 143 | $this->help(); 144 | } 145 | 146 | if (!$this->argExists('config')) { 147 | throw new Exception("the config arg is required"); 148 | } 149 | 150 | $this->config_file = $this->arg('config'); 151 | if (!file_exists($this->config_file) || !is_readable($this->config_file)) { 152 | $message = "config file is not exists or is not readable"; 153 | throw new RuntimeException($message); 154 | } 155 | $this->missions = include $this->config_file; 156 | 157 | if ($this->argExists('port')) { 158 | $this->port = $this->arg('port'); 159 | } 160 | 161 | if ($this->argExists('pid-file')) { 162 | $this->pid_file = $this->arg('pid-file'); 163 | } 164 | 165 | if ($this->argExists('log')) { 166 | $this->log = $this->arg('log'); 167 | } 168 | } 169 | 170 | /** 171 | * @return \Jenner\Crontab\AbstractDaemon 172 | */ 173 | public function factory() 174 | { 175 | $logger = new \Monolog\Logger('php_crontab'); 176 | $logger->pushHandler(new \Monolog\Handler\StreamHandler($this->log)); 177 | if (!empty($this->port)) { 178 | return new \Jenner\Crontab\HttpDaemon($this->missions, $logger, $this->port); 179 | } 180 | return new \Jenner\Crontab\Daemon($this->missions, $logger); 181 | } 182 | 183 | /** 184 | * @param $name 185 | * @return bool 186 | */ 187 | protected function argExists($name) 188 | { 189 | if (array_key_exists($name, $this->params)) { 190 | return true; 191 | } elseif (array_key_exists($this->args[$name], $this->params)) { 192 | return true; 193 | } elseif (array_key_exists(rtrim($this->args[$name . ':'], ':'), $this->params)) { 194 | return true; 195 | } 196 | 197 | return false; 198 | } 199 | 200 | /** 201 | * @param $name 202 | * @return null 203 | */ 204 | protected function arg($name) 205 | { 206 | if (array_key_exists($name, $this->params)) { 207 | return $this->params[$name]; 208 | } elseif (array_key_exists(rtrim($this->args[$name . ':'], ':'), $this->params)) { 209 | return $this->params[rtrim($this->args[$name . ':'], ':')]; 210 | } 211 | 212 | return null; 213 | } 214 | 215 | /** 216 | * 217 | */ 218 | public function keepPidFile() 219 | { 220 | $this->keep_pid_file = true; 221 | } 222 | 223 | public function deletePidFile() 224 | { 225 | if (file_exists($this->pid_file) && !$this->keep_pid_file) { 226 | @unlink($this->pid_file); 227 | } 228 | } 229 | 230 | /** 231 | * 232 | */ 233 | public function __destruct() 234 | { 235 | $this->deletePidFile(); 236 | } 237 | 238 | 239 | } -------------------------------------------------------------------------------- /bin/php_crontab: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PHP_CRONTAB_HOME=$(dirname $(cd "$(dirname "$0")"; pwd)) 3 | cd $PHP_CRONTAB_HOME 4 | php bin/crontab.php $@ 5 | 6 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jenner/crontab", 3 | "description": "php crontab base on pcntl and libev", 4 | "license": "MIT", 5 | "keywords": [ 6 | "crontab", 7 | "php crontab", 8 | "crontab manager" 9 | ], 10 | "version": "v1.5.1", 11 | "authors": [ 12 | { 13 | "name": "Jenner", 14 | "email": "hypxm@qq.com", 15 | "homepage" : "http://www.huyanping.cn" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.4.0", 20 | "ext-posix": "*", 21 | "jenner/simple_fork": "1.1.*", 22 | "monolog/monolog": "1.17.*", 23 | "react/http": "v0.4.*", 24 | "symfony/process": "v2.7.*" 25 | }, 26 | "require-dev": { 27 | "guzzle/guzzle": "v3.9.*", 28 | "ext-redis": "*" 29 | }, 30 | "suggest": { 31 | "ext-libevent": "0.1.*", 32 | "ext-event": "~1.0", 33 | "ext-libev": "*", 34 | "guzzle/guzzle": "v3.9.*", 35 | "ext-redis": "*" 36 | }, 37 | "autoload": { 38 | "psr-0": { 39 | "Jenner\\Crontab": "src/" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/daemon.php: -------------------------------------------------------------------------------- 1 | 'ls', 19 | 'cmd' => "ls -al", 20 | 'out' => '/tmp/php_crontab.log', 21 | 'time' => '* * * * *', 22 | 'user' => 'www', 23 | 'group' => 'www' 24 | ], 25 | [ 26 | 'name' => 'ls', 27 | 'cmd' => "ls -al", 28 | 'out' => '/tmp/php_crontab.log', 29 | 'time' => '* * * * *', 30 | 'user' => 'www', 31 | 'group' => 'www' 32 | ], 33 | ]; 34 | 35 | $daemon = new \Jenner\Crontab\Daemon($missions); 36 | $daemon->start(); -------------------------------------------------------------------------------- /example/http_daemon.php: -------------------------------------------------------------------------------- 1 | 'ls', 19 | 'cmd' => "ls -al", 20 | 'out' => '/tmp/php_crontab.log', 21 | 'time' => '* * * * *', 22 | ], 23 | [ 24 | 'name' => 'hostname', 25 | 'cmd' => "hostname", 26 | 'out' => '/tmp/php_crontab.log', 27 | 'time' => '* * * * *', 28 | ], 29 | ]; 30 | 31 | $logger = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 32 | $logger->pushHandler(new \Monolog\Handler\StreamHandler("/var/log/php_crontab.log")); 33 | try{ 34 | $http_daemon = new \Jenner\Crontab\HttpDaemon($missions, $logger); 35 | $http_daemon->start(); 36 | }catch(Exception $e) { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /example/simple.php: -------------------------------------------------------------------------------- 1 | 'ls', 19 | 'cmd' => "ls -al", 20 | 'out' => '/tmp/ls-al.log', 21 | 'time' => '* * * * *', 22 | 'user' => 'www', 23 | 'group' => 'www' 24 | ], 25 | [ 26 | 'name' => 'hostname', 27 | 'cmd' => "hostname", 28 | 'out' => '/tmp/hostname.log', 29 | 'time' => '* * * * *', 30 | ], 31 | ]; 32 | 33 | 34 | 35 | $tasks = array(); 36 | foreach($missions as $mission){ 37 | $logger = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 38 | $logger->pushHandler(new \Monolog\Handler\StreamHandler($mission['out'])); 39 | $tasks[] = new \Jenner\Crontab\Mission( 40 | $mission['name'], 41 | $mission['cmd'], 42 | $mission['time'], 43 | $logger 44 | ); 45 | } 46 | 47 | $logger = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 48 | $logger->pushHandler(new \Monolog\Handler\StreamHandler("/var/log/php_crontab.log")); 49 | 50 | $crontab_server = new \Jenner\Crontab\Crontab($logger, $tasks); 51 | $crontab_server->start(time()); 52 | -------------------------------------------------------------------------------- /example/task_loader.php: -------------------------------------------------------------------------------- 1 | 'ls', 17 | 'cmd' => "ls -al", 18 | 'out' => '/tmp/php_crontab.log', 19 | 'time' => '* * * * *', 20 | 'user' => 'www', 21 | 'group' => 'www' 22 | ], 23 | [ 24 | 'name' => 'ls', 25 | 'cmd' => "ls -al", 26 | 'out' => '/tmp/php_crontab.log', 27 | 'time' => '* * * * *', 28 | 'user' => 'www', 29 | 'group' => 'www' 30 | ], 31 | ]; 32 | 33 | return $missions; 34 | } 35 | 36 | 37 | $daemon = new \Jenner\Crontab\Daemon(); 38 | $daemon->registerTaskLoader("task_loader"); 39 | $daemon->start(); -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Jenner/Crontab/AbstractDaemon.php: -------------------------------------------------------------------------------- 1 | setLogger($logger); 34 | } 35 | 36 | /** 37 | * set logger 38 | * @param LoggerInterface $logger 39 | */ 40 | public function setLogger(LoggerInterface $logger) 41 | { 42 | $this->logger = $logger; 43 | } 44 | 45 | public function correctTime() 46 | { 47 | 48 | } 49 | 50 | /** 51 | * start crontab and loop 52 | */ 53 | abstract public function start(); 54 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Crontab.php: -------------------------------------------------------------------------------- 1 | logger = new Logger(self::NAME); 43 | $this->logger->pushHandler(new NullHandler()); 44 | } else { 45 | $this->logger = $logger; 46 | } 47 | 48 | $this->batchAddMissions($missions); 49 | } 50 | 51 | /** 52 | * @param Mission $mission 53 | */ 54 | public function addMission(Mission $mission) 55 | { 56 | array_push($this->missions, $mission); 57 | } 58 | 59 | /** 60 | * @param array $missions 61 | */ 62 | public function batchAddMissions($missions) 63 | { 64 | foreach ($missions as $mission) { 65 | $this->addMission($mission); 66 | } 67 | } 68 | 69 | /** 70 | * @param integer $time start time 71 | */ 72 | public function start($time = null) 73 | { 74 | try { 75 | if (is_null($time)) $time = time(); 76 | $this->start_time = $time; 77 | $this->logger->info( 78 | "start. date:" . date("Y-m-d H:i:s", $time) . ". pid:" . getmypid()); 79 | $pool = new Pool(); 80 | 81 | foreach ($this->missions as $mission) { 82 | if (!$mission->needRun($time)) continue; 83 | try { 84 | $pool->execute($mission); 85 | } catch (\Exception $e) { 86 | $this->logException($e); 87 | } 88 | } 89 | 90 | $pool->wait(); 91 | } catch (\Exception $e) { 92 | $this->logException($e); 93 | } 94 | 95 | unset($pool); 96 | } 97 | 98 | 99 | /** 100 | * @param \Exception $e 101 | */ 102 | protected function logException(\Exception $e) 103 | { 104 | $message = "Exception. message:" . $e->getMessage() . 105 | ". code:" . $e->getCode() . PHP_EOL . 106 | ". trace:" . json_encode($e->getTrace(), true); 107 | 108 | $this->logger->error($message); 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Daemon.php: -------------------------------------------------------------------------------- 1 | [ 22 | * 'name'=>'task_name', 23 | * 'cmd'=>'shell command', 24 | * 'out'=>'output file or instance of LoggerInterface', 25 | * 'err'=>'errout file or instance of LoggerInterface' 26 | * 'time'=>'* * * * *', 27 | * 'user'=>'process user', 28 | * 'group'=>'process group', 29 | * 'comment'=>'comment', 30 | * ] 31 | * ] 32 | */ 33 | protected $tasks = array(); 34 | 35 | /** 36 | * @var callable task loader, execute every 60 second 37 | */ 38 | protected $task_loader; 39 | 40 | /** 41 | * @param $tasks array 42 | * @param LoggerInterface $logger 43 | */ 44 | public function __construct($tasks = array(), LoggerInterface $logger = null) 45 | { 46 | $this->setTasks($tasks); 47 | 48 | if (is_null($logger)) { 49 | $logger = new Logger(Crontab::NAME); 50 | $logger->pushHandler(new NullHandler()); 51 | } 52 | 53 | parent::__construct($logger); 54 | } 55 | 56 | /** 57 | * start crontab and loop 58 | */ 59 | public function start() 60 | { 61 | $this->logger->info("crontab start"); 62 | $crontab = $this->createCrontab(); 63 | $loop = Factory::create(); 64 | 65 | // add periodic timer 66 | $loop->addPeriodicTimer(60, function () use ($crontab, $loop) { 67 | $loop->addTimer(60 - time() % 60, function () use ($crontab) { 68 | $pid = pcntl_fork(); 69 | if ($pid > 0) { 70 | return; 71 | } elseif ($pid == 0) { 72 | $crontab->start(time()); 73 | exit(); 74 | } else { 75 | $this->logger->error("could not fork"); 76 | } 77 | }); 78 | }); 79 | 80 | // recover the sub processes 81 | $loop->addPeriodicTimer(60, function () { 82 | while (($pid = pcntl_waitpid(0, $status, WNOHANG)) > 0) { 83 | $message = "process exit. pid:" . $pid . ". exit code:" . $status; 84 | $this->logger->info($message); 85 | } 86 | }); 87 | 88 | $loop->run(); 89 | } 90 | 91 | /** 92 | * create crontab object 93 | * 94 | * @return Crontab 95 | */ 96 | protected function createCrontab() 97 | { 98 | $tasks = $this->formatTasks(); 99 | $missions = array(); 100 | foreach ($tasks as $task) { 101 | if ($task['out'] instanceof LoggerInterface) { 102 | $out = $task['out']; 103 | } else { 104 | $out = MissionLoggerFactory::create($task['out']); 105 | } 106 | if ($task['err'] instanceof LoggerInterface) { 107 | $err = $task['err']; 108 | } else { 109 | $err = MissionLoggerFactory::create($task['err']); 110 | } 111 | 112 | $mission = new Mission( 113 | $task['name'], 114 | $task['cmd'], 115 | $task['time'], 116 | $out, 117 | $err, 118 | $task['user'], 119 | $task['group'] 120 | ); 121 | $missions[] = $mission; 122 | } 123 | 124 | return new Crontab($this->logger, $missions); 125 | } 126 | 127 | /** 128 | * format mission 129 | * 130 | * @return array 131 | */ 132 | protected function formatTasks() 133 | { 134 | $tasks = []; 135 | foreach ($this->tasks as $task) { 136 | array_key_exists('user', $task) ? null : $task['user'] = null; 137 | array_key_exists('group', $task) ? null : $task['group'] = null; 138 | $tasks[] = $task; 139 | } 140 | 141 | return $tasks; 142 | } 143 | 144 | /** 145 | * @param $tasks 146 | */ 147 | public function addTasks($tasks) 148 | { 149 | $must = array('name', 'cmd', 'time'); 150 | foreach ($tasks as $task) { 151 | $this->addTask($task); 152 | } 153 | } 154 | 155 | /** 156 | * @param $task 157 | */ 158 | public function addTask($task) 159 | { 160 | $must = array('name', 'cmd', 'time'); 161 | foreach ($must as $key) { 162 | if (!array_key_exists($key, $task)) { 163 | $message = "task must have a {$key} value"; 164 | throw new \InvalidArgumentException($message); 165 | } 166 | } 167 | 168 | $this->tasks[$task['name']] = $task; 169 | } 170 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/HTTP/Server.php: -------------------------------------------------------------------------------- 1 | 'add', 39 | 'get_by_name' => 'getByName', 40 | 'remove_by_name' => 'removeByName', 41 | 'clear' => 'clear', 42 | 'get' => 'missions', 43 | 'start' => 'begin', 44 | 'stop' => 'stop', 45 | ); 46 | 47 | /** 48 | * @param $loop 49 | * @param HttpDaemon $daemon 50 | * @param TimerInterface $crontab_timer 51 | */ 52 | public function __construct($loop, HttpDaemon $daemon, TimerInterface $crontab_timer) 53 | { 54 | $this->loop = $loop; 55 | $this->daemon = $daemon; 56 | $this->crontab_timer = $crontab_timer; 57 | } 58 | 59 | /** 60 | * @param int $port 61 | * @throws \React\Socket\ConnectionException 62 | */ 63 | public function start($port = 6364) 64 | { 65 | $socket = new \React\Socket\Server($this->loop); 66 | 67 | $http = new \React\Http\Server($socket); 68 | $http->on('request', function (Request $request, Response $response) { 69 | $path = trim($request->getPath(), '/'); 70 | if (!array_key_exists($path, $this->routes)) { 71 | $this->response($response, 0, "method not found", 101); 72 | return null; 73 | } 74 | 75 | $query_info = $request->getQuery(); 76 | $method = array($this, $this->routes[$path]); 77 | return call_user_func($method, $query_info, $response); 78 | }); 79 | 80 | $socket->listen($port); 81 | } 82 | 83 | /** 84 | * @param $params 85 | * @param Response $response 86 | */ 87 | protected function add($params, Response $response) 88 | { 89 | $must = array('name', 'cmd', 'time'); 90 | foreach ($must as $key) { 91 | if (!array_key_exists($key, $params)) { 92 | $this->response($response, 0, "missing param `{$key}`"); 93 | return; 94 | } 95 | } 96 | 97 | $this->daemon->add($params); 98 | $this->response($response, 1); 99 | } 100 | 101 | /** 102 | * @param $params 103 | * @param Response $response 104 | */ 105 | protected function getByName($params, Response $response) 106 | { 107 | if (!array_key_exists('name', $params)) { 108 | $this->response($response, 0, "missing param `name`"); 109 | return; 110 | } 111 | 112 | $name = $params['name']; 113 | $task = $this->daemon->getByName($name); 114 | if ($task !== false) { 115 | $this->response($response, 1, $task); 116 | return; 117 | } 118 | 119 | $this->response($response, 0, "mission {$name} is not exists"); 120 | } 121 | 122 | /** 123 | * @param $params 124 | * @param Response $response 125 | */ 126 | protected function removeByName($params, Response $response) 127 | { 128 | if (!array_key_exists('name', $params)) { 129 | $this->response($response, 0, "missing param name"); 130 | return; 131 | } 132 | 133 | $name = $params['name']; 134 | $this->daemon->removeByName($name); 135 | $this->response($response, 1); 136 | } 137 | 138 | /** 139 | * @param Response $response 140 | */ 141 | protected function clear($params, Response $response) 142 | { 143 | $this->daemon->clear(); 144 | $this->response($response, 1); 145 | } 146 | 147 | /** 148 | * @param Response $response 149 | */ 150 | protected function missions($params, Response $response) 151 | { 152 | $this->response($response, 1, $this->daemon->get()); 153 | } 154 | 155 | /** 156 | * @param $params 157 | * @param Response $response 158 | */ 159 | protected function begin($params, Response $response) 160 | { 161 | $this->loop->addPeriodicTimer(60, array($this->daemon, 'crontabCallback')); 162 | $this->response($response, 1); 163 | } 164 | 165 | /** 166 | * @param $params 167 | * @param Response $response 168 | */ 169 | protected function stop($params, Response $response) 170 | { 171 | $this->loop->cancelTimer($this->crontab_timer); 172 | $this->response($response, 1); 173 | } 174 | 175 | /** 176 | * @param Response $response 177 | * @param $status 178 | * @param null $data 179 | * @param int $code 180 | * @throws \Exception 181 | */ 182 | protected function response(Response $response, $status, $data = null, $code = 0) 183 | { 184 | $response->writeHead(200, array('Content-Type' => 'text/plain')); 185 | $response_data = array( 186 | 'status' => $status, 187 | 'code' => $code, 188 | ); 189 | is_null($data) ? null : $response_data['data'] = $data; 190 | $body = json_encode($response_data); 191 | 192 | $response->end($body); 193 | } 194 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/HttpDaemon.php: -------------------------------------------------------------------------------- 1 | port = $port; 32 | } 33 | 34 | /** 35 | * start crontab and loop 36 | */ 37 | public function start() 38 | { 39 | $this->logger->info("crontab start"); 40 | 41 | $loop = Factory::create(); 42 | 43 | // add periodic timer 44 | $crontab_timer = $loop->addPeriodicTimer(60, array($this, 'crontabCallback')); 45 | 46 | // recover the sub processes 47 | $loop->addPeriodicTimer(60, array($this, 'processRecoverCallback')); 48 | 49 | $server = new \Jenner\Crontab\HTTP\Server($loop, $this, $crontab_timer); 50 | $server->start($this->port); 51 | 52 | $loop->run(); 53 | } 54 | 55 | /** 56 | * start crontab every minute 57 | */ 58 | public function crontabCallback(Crontab $crontab, LoopInterface $loop) 59 | { 60 | $loop->addTimer(60 - time() % 60, function () use ($crontab) { 61 | $pid = pcntl_fork(); 62 | if ($pid > 0) { 63 | return; 64 | } elseif ($pid == 0) { 65 | $crontab->start(time()); 66 | exit(); 67 | } else { 68 | $this->logger->error("could not fork"); 69 | exit(); 70 | } 71 | }); 72 | } 73 | 74 | /** 75 | * recover the sub processes 76 | */ 77 | public function processRecoverCallback() 78 | { 79 | while (($pid = pcntl_waitpid(0, $status, WNOHANG)) > 0) { 80 | $message = "process exit. pid:" . $pid . ". exit code:" . $status; 81 | $this->logger->info($message); 82 | } 83 | } 84 | 85 | /** 86 | * add task 87 | * @param $task 88 | */ 89 | public function add($task) 90 | { 91 | $this->tasks[$task['name']] = $task; 92 | } 93 | 94 | /** 95 | * get task by name 96 | * @param $name 97 | * @return bool 98 | */ 99 | public function getByName($name) 100 | { 101 | if (array_key_exists($name, $this->tasks)) { 102 | return $this->tasks[$name]; 103 | } 104 | 105 | return false; 106 | } 107 | 108 | /** 109 | * remove task by name 110 | * @param $name 111 | */ 112 | public function removeByName($name) 113 | { 114 | unset($this->tasks[$name]); 115 | } 116 | 117 | /** 118 | * clear all tasks 119 | */ 120 | public function clear() 121 | { 122 | unset($this->tasks); 123 | $this->tasks = array(); 124 | } 125 | 126 | /** 127 | * get all tasks 128 | * @return array 129 | */ 130 | public function get() 131 | { 132 | return $this->tasks; 133 | } 134 | 135 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Mission.php: -------------------------------------------------------------------------------- 1 | name = $name; 77 | $this->cmd = $cmd; 78 | $this->time = $time; 79 | $this->user = $user; 80 | $this->group = $group; 81 | $this->comment = $comment; 82 | 83 | if (is_null($out)) { 84 | $this->out = new Logger(Crontab::NAME); 85 | $this->out->pushHandler(new NullHandler()); 86 | } else { 87 | $this->out = $out; 88 | } 89 | if (is_null($err)) { 90 | $this->err = new Logger(Crontab::NAME); 91 | $this->err->pushHandler(new NullHandler()); 92 | } else { 93 | $this->err = $err; 94 | } 95 | } 96 | 97 | /** 98 | * @return string 99 | */ 100 | public function getName() 101 | { 102 | return $this->name; 103 | } 104 | 105 | /** 106 | * @param string $name 107 | */ 108 | public function setName($name) 109 | { 110 | $this->name = $name; 111 | } 112 | 113 | /** 114 | * @return string 115 | */ 116 | public function getCmd() 117 | { 118 | return $this->cmd; 119 | } 120 | 121 | /** 122 | * @param string $cmd 123 | */ 124 | public function setCmd($cmd) 125 | { 126 | $this->cmd = $cmd; 127 | } 128 | 129 | /** 130 | * @return LoggerInterface 131 | */ 132 | public function getOut() 133 | { 134 | return $this->out; 135 | } 136 | 137 | /** 138 | * @param LoggerInterface $out 139 | */ 140 | public function setOut(LoggerInterface $out) 141 | { 142 | $this->out = $out; 143 | } 144 | 145 | /** 146 | * @return LoggerInterface 147 | */ 148 | public function getErr() 149 | { 150 | return $this->err; 151 | } 152 | 153 | /** 154 | * @param LoggerInterface $err 155 | */ 156 | public function setErr(LoggerInterface $err) 157 | { 158 | $this->err = $err; 159 | } 160 | 161 | /** 162 | * @return string 163 | */ 164 | public function getUser() 165 | { 166 | return $this->user; 167 | } 168 | 169 | /** 170 | * @param string $user 171 | */ 172 | public function setUser($user) 173 | { 174 | $this->user = $user; 175 | } 176 | 177 | /** 178 | * @return string 179 | */ 180 | public function getGroup() 181 | { 182 | return $this->group; 183 | } 184 | 185 | /** 186 | * @param string $group 187 | */ 188 | public function setGroup($group) 189 | { 190 | $this->group = $group; 191 | } 192 | 193 | /** 194 | * @return string 195 | */ 196 | public function getComment() 197 | { 198 | return $this->comment; 199 | } 200 | 201 | /** 202 | * @param string $comment 203 | */ 204 | public function setComment($comment) 205 | { 206 | $this->comment = $comment; 207 | } 208 | 209 | /** 210 | * get or set err 211 | * 212 | * @param LoggerInterface $err 213 | * @return null|string 214 | */ 215 | public function err(LoggerInterface $err = null) 216 | { 217 | if (!is_null($err)) { 218 | $this->err = $err; 219 | } else { 220 | return $this->err; 221 | } 222 | } 223 | 224 | /** 225 | * if the time is right 226 | * 227 | * @param $time 228 | * @return bool 229 | */ 230 | public function needRun($time) 231 | { 232 | if ($time - CrontabParse::parse($this->getTime(), $time) == 0) { 233 | return true; 234 | } 235 | return false; 236 | } 237 | 238 | /** 239 | * @return string 240 | */ 241 | public function getTime() 242 | { 243 | return $this->time; 244 | } 245 | 246 | /** 247 | * @param string $time 248 | */ 249 | public function setTime($time) 250 | { 251 | $this->time = $time; 252 | } 253 | 254 | /** 255 | * @return array 256 | */ 257 | public function info() 258 | { 259 | return array( 260 | 'name' => $this->name, 261 | 'cmd' => $this->cmd, 262 | 'time' => $this->time, 263 | 'out' => $this->out, 264 | 'err' => $this->err, 265 | 'user' => $this->user, 266 | 'group' => $this->group, 267 | 'comment' => $this->comment, 268 | ); 269 | } 270 | 271 | /** 272 | * start mission process 273 | */ 274 | public function run() 275 | { 276 | $this->setUserAndGroup(); 277 | 278 | $out = $this->out; 279 | $err = $this->err; 280 | $process = new \Symfony\Component\Process\Process($this->cmd, null, null, null, null); 281 | $process->run(function ($type, $buffer) use ($out, $err) { 282 | if ($type == \Symfony\Component\Process\Process::ERR) { 283 | $err->error($buffer); 284 | } else { 285 | $out->info($buffer); 286 | } 287 | }); 288 | } 289 | 290 | /** 291 | * set user and group if they are not null 292 | */ 293 | protected function setUserAndGroup() 294 | { 295 | if (!is_null($this->user)) { 296 | if (!is_null($this->group)) { 297 | $group_info = posix_getgrnam($this->group); 298 | $group_id = $group_info['gid']; 299 | if (!posix_setgid($group_id)) { 300 | throw new \RuntimeException("set group failed"); 301 | } 302 | } 303 | $user_info = posix_getpwnam($this->user); 304 | $user_id = $user_info["uid"]; 305 | if (!posix_setuid($user_id)) { 306 | throw new \RuntimeException("set user failed"); 307 | } 308 | } 309 | } 310 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/MissionLoggerFactory.php: -------------------------------------------------------------------------------- 1 | pushHandler(new StreamHandler($file)); 25 | return $logger; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Parser/ConfigParse.php: -------------------------------------------------------------------------------- 1 | getTask(); 31 | } 32 | 33 | return $tasks; 34 | } 35 | 36 | 37 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Parser/CrontabParse.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright: Copyright (C) 2009, Jan Konieczny 15 | * 16 | * This is a simple script to parse crontab syntax to get the execution time 17 | * 18 | * Eg.: $timestamp = Crontab::parse('12 * * * 1-5'); 19 | * 20 | * 21 | * This program is free software: you can redistribute it and/or modify 22 | * it under the terms of the GNU General Public License as published by 23 | * the Free Software Foundation, either version 3 of the License, or 24 | * (at your option) any later version. 25 | * 26 | * This program is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | * GNU General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU General Public License 32 | * along with this program. If not, see . 33 | */ 34 | /** 35 | * Provides basic cron syntax parsing functionality 36 | * 37 | * @author: Jan Konieczny 38 | * @copyright: Copyright (C) 2009, Jan Konieczny 39 | */ 40 | class CrontabParse 41 | { 42 | /** 43 | * Finds next execution time(stamp) parsin crontab syntax, 44 | * after given starting timestamp (or current time if ommited) 45 | * 46 | * @param string $_cron_string : 47 | * 48 | * 0 1 2 3 4 49 | * * * * * * 50 | * - - - - - 51 | * | | | | | 52 | * | | | | +----- day of week (0 - 6) (Sunday=0) 53 | * | | | +------- month (1 - 12) 54 | * | | +--------- day of month (1 - 31) 55 | * | +----------- hour (0 - 23) 56 | * +------------- min (0 - 59) 57 | * @param int $_after_timestamp timestamp [default=current timestamp] 58 | * @return int unix timestamp - next execution time will be greater 59 | * than given timestamp (defaults to the current timestamp) 60 | * @throws \InvalidArgumentException 61 | */ 62 | public static function parse($_cron_string, $_after_timestamp = null) 63 | { 64 | if (!preg_match('/^((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)\s+((\*(\/[0-9]+)?)|[0-9\-\,\/]+)$/i', trim($_cron_string))) { 65 | throw new \InvalidArgumentException("Invalid cron string: " . $_cron_string); 66 | } 67 | if ($_after_timestamp && !is_numeric($_after_timestamp)) { 68 | throw new \InvalidArgumentException("\$_after_timestamp must be a valid unix timestamp ($_after_timestamp given)"); 69 | } 70 | $cron = preg_split("/[\s]+/i", trim($_cron_string)); 71 | $start = empty($_after_timestamp) ? time() : $_after_timestamp; 72 | $date = array('minutes' => self::_parseCronNumbers($cron[0], 0, 59), 73 | 'hours' => self::_parseCronNumbers($cron[1], 0, 23), 74 | 'dom' => self::_parseCronNumbers($cron[2], 1, 31), 75 | 'month' => self::_parseCronNumbers($cron[3], 1, 12), 76 | 'dow' => self::_parseCronNumbers($cron[4], 0, 6), 77 | ); 78 | // limited to time()+366 - no need to check more than 1year ahead 79 | for ($i = 0; $i <= 60 * 60 * 24 * 366; $i += 60) { 80 | if (in_array(intval(date('j', $start + $i)), $date['dom']) && 81 | in_array(intval(date('n', $start + $i)), $date['month']) && 82 | in_array(intval(date('w', $start + $i)), $date['dow']) && 83 | in_array(intval(date('G', $start + $i)), $date['hours']) && 84 | in_array(intval(date('i', $start + $i)), $date['minutes']) 85 | ) { 86 | return $start + $i; 87 | } 88 | } 89 | return null; 90 | } 91 | 92 | /** 93 | * get a single cron style notation and parse it into numeric value 94 | * 95 | * @param string $s cron string element 96 | * @param int $min minimum possible value 97 | * @param int $max maximum possible value 98 | * @return int parsed number 99 | */ 100 | protected static function _parseCronNumbers($s, $min, $max) 101 | { 102 | $result = array(); 103 | $v = explode(',', $s); 104 | foreach ($v as $vv) { 105 | $vvv = explode('/', $vv); 106 | $step = empty($vvv[1]) ? 1 : $vvv[1]; 107 | $vvvv = explode('-', $vvv[0]); 108 | $_min = count($vvvv) == 2 ? $vvvv[0] : ($vvv[0] == '*' ? $min : $vvv[0]); 109 | $_max = count($vvvv) == 2 ? $vvvv[1] : ($vvv[0] == '*' ? $max : $vvv[0]); 110 | for ($i = $_min; $i <= $_max; $i += $step) { 111 | $result[$i] = intval($i); 112 | } 113 | } 114 | ksort($result); 115 | 116 | return $result; 117 | } 118 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Parser/JobParse.php: -------------------------------------------------------------------------------- 1 | parse($raw); 31 | } 32 | } 33 | 34 | /** 35 | * @param null $time 36 | * @return null 37 | */ 38 | public function time($time = null) 39 | { 40 | if (!is_null($time)) { 41 | $this->time = $time; 42 | } else { 43 | return $this->time; 44 | } 45 | } 46 | 47 | /** 48 | * @param null $command 49 | * @return mixed 50 | */ 51 | public function command($command = null) 52 | { 53 | if (!is_null($command)) { 54 | $this->command = $command; 55 | } else { 56 | return $this->command; 57 | } 58 | } 59 | 60 | /** 61 | * @param $raw 62 | */ 63 | public function parse($raw) 64 | { 65 | $info = preg_split('/\s+/', $raw); 66 | $time_info = array_slice($info, 0, 5); 67 | $this->time = implode(' ', $time_info); 68 | 69 | $this->command = implode(' ', array_slice($info, 5)); 70 | } 71 | 72 | /** 73 | * @return string 74 | */ 75 | public function render() 76 | { 77 | $raw = $this->time . ' ' . $this->command; 78 | 79 | return $raw; 80 | } 81 | 82 | /** 83 | * @return array 84 | */ 85 | public function getTask() 86 | { 87 | $name = uniqid('cron-', true) . mt_rand(0, 1000000); 88 | return array( 89 | 'name' => $name, 90 | 'time' => $this->time, 91 | 'cmd' => $this->command, 92 | ); 93 | } 94 | } -------------------------------------------------------------------------------- /src/Jenner/Crontab/Parser/README.MD: -------------------------------------------------------------------------------- 1 | Contab Config File Parser 2 | ============================== 3 | not stable -------------------------------------------------------------------------------- /tests/CrontabTest.php: -------------------------------------------------------------------------------- 1 | setFormatter(new \Monolog\Formatter\LineFormatter("%message%", "", true)); 20 | $logger->pushHandler($stream); 21 | $mission = new \Jenner\Crontab\Mission("mission_test", "ls /", "* * * * *", $logger); 22 | $crontab = new \Jenner\Crontab\Crontab(null, array($mission)); 23 | 24 | $crontab->start(time()); 25 | $out = file_get_contents($log_file); 26 | $except = shell_exec("ls /"); 27 | $this->assertEquals($out, $except); 28 | } 29 | 30 | public function testError() 31 | { 32 | $log_file = "/tmp/test_error.log"; 33 | $err_file = "/tmp/test_error_err.log"; 34 | if(file_exists($log_file)) { 35 | unlink($log_file); 36 | } 37 | if(file_exists($err_file)) { 38 | unlink($err_file); 39 | } 40 | $out = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 41 | $stream = new \Monolog\Handler\StreamHandler($log_file); 42 | $stream->setFormatter(new \Monolog\Formatter\LineFormatter("%message%", "", true)); 43 | $out->pushHandler($stream);; 44 | $err = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 45 | $stream = new \Monolog\Handler\StreamHandler($err_file); 46 | $stream->setFormatter(new \Monolog\Formatter\LineFormatter("%message%", "", true)); 47 | $err->pushHandler($stream); 48 | $mission = new \Jenner\Crontab\Mission("mission_test", "ls / && command_not_exists", "* * * * *", $out, $err); 49 | $crontab = new \Jenner\Crontab\Crontab(null, array($mission)); 50 | 51 | $crontab->start(time()); 52 | $stdout = file_get_contents($log_file); 53 | $except = shell_exec("ls /"); 54 | $this->assertEquals($stdout, $except); 55 | $stderr = file_get_contents($err_file); 56 | $except = shell_exec('command_not_exists 2>&1'); 57 | $this->assertEquals($stderr, $except); 58 | } 59 | 60 | public function testNotStart() 61 | { 62 | $log_file = "/tmp/test_not_start.log"; 63 | if(file_exists($log_file)) { 64 | unlink($log_file); 65 | } 66 | $logger = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 67 | $stream = new \Monolog\Handler\StreamHandler($log_file); 68 | $stream->setFormatter(new \Monolog\Formatter\LineFormatter("%message%", "", true)); 69 | $logger->pushHandler($stream); 70 | $mission = new \Jenner\Crontab\Mission("mission_test", "ls /", "3 * * * *", $logger); 71 | $crontab = new \Jenner\Crontab\Crontab(null, array($mission)); 72 | 73 | $crontab->start(time()); 74 | $this->assertFalse(file_exists($log_file)); 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /tests/CustomHandler.php: -------------------------------------------------------------------------------- 1 | param_1 = $param_1; 16 | $this->param_2 = $param_2; 17 | } 18 | 19 | /** 20 | * Checks whether the given record will be handled by this handler. 21 | * 22 | * This is mostly done for performance reasons, to avoid calling processors for nothing. 23 | * 24 | * Handlers should still check the record levels within handle(), returning false in isHandling() 25 | * is no guarantee that handle() will not be called, and isHandling() might not be called 26 | * for a given record. 27 | * 28 | * @param array $record Partial log record containing only a level key 29 | * 30 | * @return Boolean 31 | */ 32 | public function isHandling(array $record) 33 | { 34 | // TODO: Implement isHandling() method. 35 | } 36 | 37 | /** 38 | * Handles a record. 39 | * 40 | * All records may be passed to this method, and the handler should discard 41 | * those that it does not want to handle. 42 | * 43 | * The return value of this function controls the bubbling process of the handler stack. 44 | * Unless the bubbling is interrupted (by returning true), the Logger class will keep on 45 | * calling further handlers in the stack with a given log record. 46 | * 47 | * @param array $record The record to handle 48 | * @return Boolean true means that this handler handled the record, and that bubbling is not permitted. 49 | * false means the record was either not processed or that this handler allows bubbling. 50 | */ 51 | public function handle(array $record) 52 | { 53 | // TODO: Implement handle() method. 54 | } 55 | 56 | /** 57 | * Handles a set of records at once. 58 | * 59 | * @param array $records The records to handle (an array of record arrays) 60 | */ 61 | public function handleBatch(array $records) 62 | { 63 | // TODO: Implement handleBatch() method. 64 | } 65 | 66 | /** 67 | * Adds a processor in the stack. 68 | * 69 | * @param callable $callback 70 | * @return self 71 | */ 72 | public function pushProcessor($callback) 73 | { 74 | // TODO: Implement pushProcessor() method. 75 | } 76 | 77 | /** 78 | * Removes the processor on top of the stack and returns it. 79 | * 80 | * @return callable 81 | */ 82 | public function popProcessor() 83 | { 84 | // TODO: Implement popProcessor() method. 85 | } 86 | 87 | /** 88 | * Sets the formatter. 89 | * 90 | * @param \Monolog\Formatter\FormatterInterface $formatter 91 | * @return self 92 | */ 93 | public function setFormatter(\Monolog\Formatter\FormatterInterface $formatter) 94 | { 95 | // TODO: Implement setFormatter() method. 96 | } 97 | 98 | /** 99 | * Gets the formatter. 100 | * 101 | * @return \Monolog\Formatter\FormatterInterface 102 | */ 103 | public function getFormatter() 104 | { 105 | // TODO: Implement getFormatter() method. 106 | } 107 | } -------------------------------------------------------------------------------- /tests/JobParseTest.php: -------------------------------------------------------------------------------- 1 | job_parser = new \Jenner\Crontab\Parser\JobParse(); 19 | } 20 | 21 | /** 22 | * @dataProvider parseProvider 23 | */ 24 | public function testParse($raw, $time, $command) 25 | { 26 | $this->job_parser->parse($raw); 27 | $this->assertEquals($this->job_parser->time(), $time); 28 | $this->assertEquals($this->job_parser->command(), $command); 29 | } 30 | 31 | public function parseProvider() 32 | { 33 | return array( 34 | array('* * * * * ls -al > test.log', '* * * * *', 'ls -al > test.log'), 35 | array('* * * * * ls -al > test.log', '* * * * *', 'ls -al > test.log'), 36 | array('* * * * * ls -al > test.log', '* * * * *', 'ls -al > test.log'), 37 | array('* * * * * ls -al > test.log', '* * * * *', 'ls -al > test.log') 38 | ); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /tests/MissionTest.php: -------------------------------------------------------------------------------- 1 | log_file)) { 24 | unlink($this->log_file); 25 | } 26 | $logger = new \Monolog\Logger(\Jenner\Crontab\Crontab::NAME); 27 | $stream = new \Monolog\Handler\StreamHandler($this->log_file); 28 | $stream->setFormatter(new \Monolog\Formatter\LineFormatter("%message%", "", true)); 29 | $logger->pushHandler($stream); 30 | 31 | $this->mission = new \Jenner\Crontab\Mission( 32 | "mission_test", 33 | "ls /", 34 | "* * * * *", 35 | $logger 36 | ); 37 | } 38 | 39 | public function testNeed() 40 | { 41 | $this->assertTrue($this->mission->needRun(time())); 42 | $this->assertTrue($this->mission->needRun(time() + 60)); 43 | $this->assertTrue($this->mission->needRun(time() + 120)); 44 | } 45 | 46 | 47 | public function testRun() 48 | { 49 | $this->mission->start(); 50 | $this->mission->wait(); 51 | $this->assertEquals($this->mission->errno(), 0); 52 | $out = file_get_contents($this->log_file); 53 | $except = shell_exec("ls /"); 54 | $this->assertEquals($out, $except); 55 | } 56 | } -------------------------------------------------------------------------------- /tests/config.php: -------------------------------------------------------------------------------- 1 | '1', 12 | 'cmd' => "date", 13 | 'out' => 'file:///tmp/date_1.log', 14 | 'err' => 'file:///tmp/date_1.log', 15 | 'time' => '* * * * *', 16 | ], 17 | [ 18 | 'name' => '2', 19 | 'cmd' => "date", 20 | 'out' => 'file:///tmp/date_2.log', 21 | 'err' => 'file:///tmp/date_2.log', 22 | 'time' => '* * * * *', 23 | ], 24 | [ 25 | 'name' => '3', 26 | 'cmd' => "date", 27 | 'out' => 'file:///tmp/date_3.log', 28 | 'err' => 'file:///tmp/date_3.log', 29 | 'time' => '* * * * *', 30 | ], 31 | [ 32 | 'name' => '4', 33 | 'cmd' => "date", 34 | 'out' => 'file:///tmp/date_4.log', 35 | 'err' => 'file:///tmp/date_4.log', 36 | 'time' => '* * * * *', 37 | ], 38 | [ 39 | 'name' => '5', 40 | 'cmd' => "date", 41 | 'out' => 'file:///tmp/date_5.log', 42 | 'err' => 'file:///tmp/date_5.log', 43 | 'time' => '* * * * *', 44 | ], 45 | [ 46 | 'name' => '6', 47 | 'cmd' => "date", 48 | 'out' => 'file:///tmp/date_6.log', 49 | 'err' => 'file:///tmp/date_6.log', 50 | 'time' => '* * * * *', 51 | ], 52 | [ 53 | 'name' => '7', 54 | 'cmd' => "date", 55 | 'out' => 'file:///tmp/date_7.log', 56 | 'err' => 'file:///tmp/date_7.log', 57 | 'time' => '* * * * *', 58 | ], 59 | [ 60 | 'name' => '8', 61 | 'cmd' => "date", 62 | 'out' => 'file:///tmp/date_8.log', 63 | 'err' => 'file:///tmp/date_8.log', 64 | 'time' => '* * * * *', 65 | ], 66 | [ 67 | 'name' => '9', 68 | 'cmd' => "date", 69 | 'out' => 'file:///tmp/date_9.log', 70 | 'err' => 'file:///tmp/date_9.log', 71 | 'time' => '* * * * *', 72 | ], 73 | ]; -------------------------------------------------------------------------------- /tests/logger.test.php: -------------------------------------------------------------------------------- 1 | setFormatter(new \Monolog\Formatter\LineFormatter("%message%\n", "Ymd")); 15 | $logger->pushHandler($stream); 16 | $logger->info("tgest "); 17 | $logger->error("test"); -------------------------------------------------------------------------------- /tests/timer.php: -------------------------------------------------------------------------------- 1 | addPeriodicTimer(10, function() { 15 | for($i=0; $i<3; $i++) { 16 | echo "function A", PHP_EOL; 17 | sleep(1); 18 | } 19 | }); 20 | 21 | $loop->addPeriodicTimer(10, function() { 22 | for($i=0; $i<3; $i++) { 23 | echo "function B", PHP_EOL; 24 | sleep(1); 25 | } 26 | }); 27 | 28 | $loop->run(); --------------------------------------------------------------------------------