{"id":3472,"date":"2016-10-11T11:01:02","date_gmt":"2016-10-11T15:01:02","guid":{"rendered":"https:\/\/www.redline13.com\/blog\/?page_id=3472"},"modified":"2022-01-17T23:41:52","modified_gmt":"2022-01-18T04:41:52","slug":"custom-load-test-php","status":"publish","type":"page","link":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/","title":{"rendered":"Custom Load Test PHP"},"content":{"rendered":"<h3>Writing Custom Load Tests<\/h3>\n<p>A language specific load test is<\/p>\n<ul>\n<li>ANY code\u00a0you want to execute<\/li>\n<li>With some redline13 API calls to report test execution and timing<\/li>\n<\/ul>\n<p>Each\u00a0language is\u00a0documented independently and can be found on the corresponding page<\/p>\n<ul>\n<li><a href=\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\">PHP<\/a><\/li>\n<li><a href=\"https:\/\/www.redline13.com\/blog\/custom-load-test-nodejs\/\">NodeJS<\/a><\/li>\n<li><a href=\"https:\/\/www.redline13.com\/blog\/custom-load-test-python\/\">Python<\/a><\/li>\n<\/ul>\n<h3>Submitting\u00a0Performance Tests<\/h3>\n<ul>\n<li>There are two ways to submit a custom load test\n<ul>\n<li>Submit the Load Test File ([ANY_NAME]..php ) in the language specified<\/li>\n<li>Submit a compressed file (.tar, .tar.gz, .tgz ) with the custom file specifically named\n<ul>\n<li>PHP &#8211; Custom.class.php<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Custom Load Tests support CSV, Compressed, and Extra files\n<ul>\n<li>CSV files can be split across servers<\/li>\n<li>Compressed files can be marked to be expanded<\/li>\n<li>All files are placed in the root of the load test<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Package Support in Load Tests<\/h3>\n<p>Each Language supports\u00a0a packaging mechanism to install more packages<\/p>\n<ul>\n<li>PHP &#8211; <a href=\"https:\/\/www.redline13.com\/blog\/2016\/07\/feature-update-composer-plugin\/\">Composer Plugin<\/a><\/li>\n<li>Just include your\u00a0composer.json file and we handle running composer command.<\/li>\n<\/ul>\n<h3>Versioning<\/h3>\n<ul>\n<li>PHP 5.5.9<\/li>\n<li>Other versions required? \u00a0email info@redline13.com<\/li>\n<\/ul>\n<h3>Test Harness for local testing<\/h3>\n<p>A\u00a0Test Harness is available for all languages, including\u00a0examples<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/redline13\/harness-custom-test-php\">PHP Harness<\/a><\/li>\n<\/ul>\n<h2 id=\"phptest\">PHP Test<\/h2>\n<p>To write a custom load test in PHP, you need to create a single PHP file that contains a class named <code>CustomTest<\/code> that extends class <code>LoadTestingTest<\/code>. The constructor for <code>CustomTest<\/code> will be called with 2 parameters, a test number and a random string, both of which should be passed to the constructor for <code>LoadTestingTest<\/code>. An instance of this class will be started for each user specified in the &#8220;Number of User&#8221; form field.<\/p>\n<p>Documentation for the <code>LoadTestingTest<\/code> class and other helper classes can be found at <a href=\"https:\/\/www.redline13.com\/customTestDoc\/index.html\">https:\/\/www.redline13.com\/customTestDoc\/index.html<\/a>. You must override the <code>startTest()<\/code> method of <code>LoadTestingTest<\/code>. This function is called to start the load test.<\/p>\n<p>There are several reporting functions that are available for your use.<\/p>\n<ul>\n<li><code>recordPageTime($ts, $time, $error = false, $kb = 0)<\/code> &#8211; This records and aggregates the total page load time for a request, with <code>$ts<\/code> being the UNIX timestamp when the request started and <code>$time<\/code> being the time to complete the request. This function is used in the UI to report the overall average response time. The <code>goToUrl<\/code> method of <code>LoadTestingSession<\/code> calls this for you.\n<ul>\n<li>$error &#8211; if your page is an ERROR you can differentiate it from a success, yet still record page time.<\/li>\n<li>$kb &#8211; record size of your response<\/li>\n<\/ul>\n<\/li>\n<li><code>recordURLPageLoad($url, $ts, $time, $error = false, $kb = 0)<\/code> &#8211; This records and aggregates the total page load time for a request to a specific URL, with <code>$ts<\/code> being the UNIX timestamp when the request started and <code>$time<\/code> being the time to complete the request. This function is used in the UI to report the per page average response time, but does not affect the overall response time that is calculated. The <code>goToUrl<\/code> and <code>loadResources<\/code> methods of <code>LoadTestingSession<\/code> calls this for you.\n<ul>\n<li>$error &#8211; boolean to record if your\u00a0result is fail or success<\/li>\n<li>$kb &#8211; Size of response.<\/li>\n<\/ul>\n<\/li>\n<li><code>recordDownloadSize($kb)<\/code> &#8211; This records the number of kilobytes downloaded for a request. The <code>goToUrl<\/code> and <code>loadResources<\/code> methods of <code>LoadTestingSession<\/code> calls this for you.\n<ul>\n<li>No longer needed\u00a0if you record size in page or url\u00a0calls.<\/li>\n<li>Can be used to record non-page specific\u00a0download size<\/li>\n<\/ul>\n<\/li>\n<li><code>recordError($error)<\/code> &#8211; This records an error that will be displayed in the UI.\n<ul>\n<li>Can be used to record general errors<\/li>\n<\/ul>\n<\/li>\n<li><code>recordProgress($testNum, $percent)<\/code> &#8211; This records the progress (between 0 and 100) of a single test. This allows you to enable more accurate progress than the default, which is based only on the number completed vs. the test size.<\/li>\n<\/ul>\n<p>If a test fails, you can throw an Exception and the test will be marked as a failure.<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/redline13\/custom-loadtests\/blob\/master\/SimpleLoadTest.php\">Click here<\/a> to download an simple example custom test written in PHP.<\/li>\n<li><a href=\"https:\/\/github.com\/redline13\/custom-loadtests\/blob\/master\/FormLoadTest.php\">Click here<\/a> to download an example custom test that simulates filling out an HTML form.<\/li>\n<li><a href=\"https:\/\/github.com\/redline13\/custom-loadtests\/blob\/master\/WebSocketLoadTest.php\">Click here<\/a> to download an example custom test for simulating WebSocket traffic.\n<ul>\n<li>composer.json for WebSocket Test is on\u00a0GitHub Repo\u00a0<a href=\"https:\/\/github.com\/redline13\/custom-loadtests\/blob\/master\/composer.json\">redline13\/custom-loadtests\/blob\/master\/composer.json<\/a>.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Tips<\/h3>\n<ul>\n<li>To simulate the iterations parameter of a simple test, use a loop around your call(s) to goToUrl.<\/li>\n<li>You can use the random string that is passed in as the second parameter to your <code>CustomTest<\/code> constructor to append to URLs. This can help you to easily identify load testing requests in your server logs.<\/li>\n<li>If you need additional resources for your test, you can download a file (e.g. a .tgz) with the resources in the <code>CustomTest<\/code> constructor. You should include code to ensure that only one test per server downloads the files. If you know the number of tests per server, you can use the test number to decide which test should download the files. Alternatively, you can attempt to create a lock file, with the first process successfully creating the lock file doing the file download.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Writing Custom Load Tests A language specific load test is ANY code\u00a0you want to execute With some redline13 API calls to report test execution and timing Each\u00a0language is\u00a0documented independently and can be found on the corresponding page PHP NodeJS Python Submitting\u00a0Performance Tests There are two ways to submit a custom load test Submit the Load Test File ([ANY_NAME]..php ) in the language specified Submit a compressed file (.tar, .tar.gz, .tgz ) with the custom file specifically<a class=\"more-link\" href=\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\">Read More &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3473,"parent":0,"menu_order":10,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":{"0":"entry","1":"page","2":"publish","3":"author-user","4":"post-3472","6":"has-post-thumbnail"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.12 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Custom Load Test PHP - RedLine13<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom Load Test PHP - RedLine13\" \/>\n<meta property=\"og:description\" content=\"Writing Custom Load Tests A language specific load test is ANY code\u00a0you want to execute With some redline13 API calls to report test execution and timing Each\u00a0language is\u00a0documented independently and can be found on the corresponding page PHP NodeJS Python Submitting\u00a0Performance Tests There are two ways to submit a custom load test Submit the Load Test File ([ANY_NAME]..php ) in the language specified Submit a compressed file (.tar, .tar.gz, .tgz ) with the custom file specificallyRead More &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\" \/>\n<meta property=\"og:site_name\" content=\"RedLine13\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-18T04:41:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2016\/10\/PHP_Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"722\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\",\"name\":\"Custom Load Test PHP - RedLine13\",\"isPartOf\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\"},\"datePublished\":\"2016-10-11T15:01:02+00:00\",\"dateModified\":\"2022-01-18T04:41:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.redline13.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom Load Test PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"name\":\"RedLine13\",\"description\":\"(Almost) Free Load Testing in the Cloud\",\"publisher\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.redline13.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\",\"name\":\"RedLine13\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"contentUrl\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"width\":300,\"height\":68,\"caption\":\"RedLine13\"},\"image\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom Load Test PHP - RedLine13","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/","og_locale":"en_US","og_type":"article","og_title":"Custom Load Test PHP - RedLine13","og_description":"Writing Custom Load Tests A language specific load test is ANY code\u00a0you want to execute With some redline13 API calls to report test execution and timing Each\u00a0language is\u00a0documented independently and can be found on the corresponding page PHP NodeJS Python Submitting\u00a0Performance Tests There are two ways to submit a custom load test Submit the Load Test File ([ANY_NAME]..php ) in the language specified Submit a compressed file (.tar, .tar.gz, .tgz ) with the custom file specificallyRead More &rarr;","og_url":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/","og_site_name":"RedLine13","article_modified_time":"2022-01-18T04:41:52+00:00","og_image":[{"width":722,"height":350,"url":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2016\/10\/PHP_Logo.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/","url":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/","name":"Custom Load Test PHP - RedLine13","isPartOf":{"@id":"https:\/\/www.redline13.com\/blog\/#website"},"datePublished":"2016-10-11T15:01:02+00:00","dateModified":"2022-01-18T04:41:52+00:00","breadcrumb":{"@id":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.redline13.com\/blog\/custom-load-test-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.redline13.com\/blog\/custom-load-test-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.redline13.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom Load Test PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.redline13.com\/blog\/#website","url":"https:\/\/www.redline13.com\/blog\/","name":"RedLine13","description":"(Almost) Free Load Testing in the Cloud","publisher":{"@id":"https:\/\/www.redline13.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.redline13.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.redline13.com\/blog\/#organization","name":"RedLine13","url":"https:\/\/www.redline13.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","contentUrl":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","width":300,"height":68,"caption":"RedLine13"},"image":{"@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/pages\/3472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/comments?post=3472"}],"version-history":[{"count":0,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/pages\/3472\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/media\/3473"}],"wp:attachment":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/media?parent=3472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}