{"id":72,"date":"2014-02-14T16:33:43","date_gmt":"2014-02-14T16:33:43","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=72"},"modified":"2014-02-14T16:33:43","modified_gmt":"2014-02-14T16:33:43","slug":"testing-using-curl","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2014\/02\/14\/testing-using-curl\/","title":{"rendered":"Testing Using Curl"},"content":{"rendered":"<p>Curl can be helpful in testing many things including web sites.<\/p>\n<p>See if curl is installed<\/p>\n<p>Using ssh:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&#x5B;root@localhost root]# which curl\n<\/pre>\n<p>This will tell you if the system has curl installed. But you need to have libcurl, and the curl PHP extension to be able to use curl in PHP. To see if it\u2019s enabled, simply do:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nphpinfo();\n<\/pre>\n<p>in a PHP file, and see what it outputs. It will list all active extensions (and some more info). CTRL-F for curl in that output.<\/p>\n<p>Check a site load time:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ntime curl -s http:\/\/www.coldriverdata.com &gt; \/dev\/null\n<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nreal    0m0.191s\nuser    0m0.004s\nsys     0m0.000s\n<\/pre>\n<p>Stress test a Site:<\/p>\n<p>The Curl syntax allows you to specify sequences and sets of URL\u2019s. Say for example we\u2019re going to run a load stress test against this site we can run\u2026<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s &quot;http:\/\/coldriverdata.com?&#x5B;1-1000]&quot;\n<\/pre>\n<p>This will make 1000 calls to coldriverdata.com i.e.<\/p>\n<p>http:\/\/coldriverdata.com?1<br \/>\nhttp:\/\/coldriverdata.com?2<br \/>\nhttp:\/\/coldriverdata.com?3<br \/>\n&#8230;<br \/>\nhttp:\/\/coldriverdata.com?1000<\/p>\n<p>So say you want to stress test your web application and it won\u2019t complain if it\u2019s fed an extra parameter, 10,000 calls could be done something like.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s &quot;http:\/\/yourappp.com\/your_page_to_test.php?&#x5B;1-10000]&quot;\n<\/pre>\n<p>Multiple Pages<\/p>\n<p>Easy just add each page to the command line.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s &quot;http:\/\/yourapp.com\/page1.php?&#x5B;1-1000]&quot; &quot;http:\/\/yourappp.com\/page2.php?&#x5B;1-1000]&quot;\n<\/pre>\n<p>Or even\u2026<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot;\n<\/pre>\n<p>Timing<\/p>\n<p>Using the time command we can get a view on our performance<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ntime curl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot;\n<\/pre>\n<p>real 0m0.606s<br \/>\nuser 0m0.009s<br \/>\nsys 0m0.008s<\/p>\n<p>Simulating consecutive users<\/p>\n<p>OK, this is great for sending a whole bunch of calls one after the other but what about simultaneous calls. For this we can place the Curl calls in a script and set them running in the background. i.e. my_stress_test.sh<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\ncurl -s &quot;http:\/\/yourapp.com\/page{1, 2}.php?&#x5B;1-1000]&quot; &amp;\npidlist=&quot;$pidlist $!&quot;\nfor job in $pidlist do\necho $job\nwait $job || let &quot;FAIL+=1&quot;\ndone\n\nif &#x5B; &quot;$FAIL&quot; == &quot;0&quot; ]; then\necho &quot;SUCCESS!&quot;\nelse\necho &quot;EPICFAIL! ($FAIL)&quot;\nfi\n<\/pre>\n<p>Then run <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ntime my_stress_test.sh\n<\/pre>\n<p>NOTE:<\/p>\n<p>This does not simulate user behaviour exactly as the browser is not only downloading the page but all attached images, javascripts, stylesheet etc. You could simulate this too by adding the URL\u2019s to the url command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Curl can be helpful in testing many things including web sites. See if curl is installed Using ssh: &#x5B;root@localhost root]# which curl This will tell you if the system has curl installed. But you need to have libcurl, and the curl PHP extension to be able to use curl in PHP. To see if it\u2019s &#8230; <a title=\"Testing Using Curl\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2014\/02\/14\/testing-using-curl\/\" aria-label=\"Read more about Testing Using Curl\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-curl"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}