Yii asynchronous method access - asynchronous

I just wanna ask something about Yii. I realize that Yii page (controller - method) cannot be access in same time (with same browser, different tab). The page must be completed process first before user can open another page.
class SiteController extends CController {
public function actionIndex() {
echo "Test1";
sleep(10);
echo "Test2"
}
public function actionIndex2() {
echo "Test1";
sleep(10);
echo "Test2";
}
}
For example, when I access http://test.com/site/index at 13.00, and http://test.com/site/index2 at 13.01, http://test.com/site/index will be rendered at 13.10 and http://test.com/site/index2 will be rendered around 13.20 or 13.21. What I am expecting is the code will run parallel, the first one will be finish in 13.10 and the second one will be finish in 13.10 or 13.11. Like php script below (rename it test.php), and run in separate tab (but same browser).
<?php
echo "Test1";
sleep(10);
echo "Test2";
?>
So Yii can response multiple request in same time without completing previous request. Same problem I found in here: http://www.yiiframework.com/forum/index.php/topic/41358-multiple-simultaneous-http-requestssolved/ and here http://www.yiiframework.com/forum/index.php/topic/11881-write-delay-with-sessionscache/
I am still finding the best solution. I'm trying this Yii framework async request and PHP Asynchronous Method Call In The Yii Framework for now...
Thanks

Related

nginx lua body_filter_by_lua_block need to execute sleep API disabled in the context of content_by_lua*

I need to make body filter sleep before response
location /configure/result.php {
body_filter_by_lua_block {
--I am using ngx.arg[1] content return here if content contains somevalue then sleep
--Need to execute sleep code before response =>
ngx.sleep(60) --API disabled in the context of content_by_lua??
}
}
}
But i cant execute sleep function in body filter API disabled in the context of content_by_lua* is there any other method i can use
I rebuild source code to be able to use sleep function in body filters but it did not work the error "no co ctx was found" some suggestions would really help me i found out that i can use the (echo_sleep 10.0;) from nginx but it does so before the content from server has been requested
You can use access_by_lua to make request to "/" but then unfortunately you will have double the data request sent

SilverStripe 4 : FunctionalTest "get" method returns 404 status although the page is there.

I am trying to test a controller with this Test class,
<?php
use SilverStripe\Dev\FunctionalTest;
class SitePageControllerTest extends FunctionalTest
{
protected static $fixture_file = 'site/tests/fixturesSitePage.yml';
public function testViewSitePage()
{
$obj = $this->objFromFixture('SitePage', 'page1');
$page = $this->get('page-one/');
$this->assertEquals(200, $page->getStatusCode());
}
}
and Fixture.
SitePage:
page1:
Title: Page One
CanViewType: true
But "$this->get('page-one/');" returns a 404 page.
Pages are versioned, and this one isn't published at the point where you ask for it, so the functional test emulates a frontend web request which is served from the live (published) stage by default.
You can use the draft site by appending ?stage=Stage to your request URL, or by using protected static $use_draft_site = true in your functional test (this is deprecated in 4.2).
Note that FunctionalTest doesn't log a user in, so you may also need to log in with some level of permission i.e. $this->logInWithPermission('ADMIN')
Another option is to publish it using something like: $obj->publishRecursive(); before the get()

phpunit test passes, page load in browser fails in Symfony 2

I am new to phpunit testing and did a very simple test looking for status code.
The test passes when I run:
bin\phpunit -c app src\AppBundle\Tests\Controller\StarLinX\TravelControllerTest.php
PHPUnit 4.6.10 by Sebastian Bergmann and contributors.
Configuration read from C:\PhpstormProjects\dir\app\phpunit.xml.dist
.
Time: 6.03 seconds, Memory: 20.00Mb
OK (1 test, 1 assertion)
But when I load the page in the browser, an exception is thrown rendering the twig file with status code 500.
I thought maybe this was a cache issue, so I cleared cache in --env=dev, prod and test.
How do I troubleshoot this error?
This is my test file:
namespace AppBundle\Tests\Controller\StarLinX;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TravelControllerTest extends WebTestCase {
public function testGET() {
// Create a new client to browse the application
$client = static::createClient();
// get the page
$crawler = $client->request('GET', '/travel/aaaaa');
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /travel/aaaaa");
}
}
This is the error that is thrown when running in the dev environment:
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion")
So after a little more analysis, I find that the error around {{ weatherInfo }} which should be {{ weatherInfo.now }}. This throws an error when running the development environment. In production, twig simply displays Array.
Is that normal behavior?
As it's written your test only check the error status, the test is not specific enough. What if it displayed another page? The test would still pass.
You should add some other tests in order to ensure that the page is properly displayed:
// …
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
"Unexpected HTTP status code for GET /travel/aaaaa");
// Check that the page has a title.
$this->assertSame(
1,
$crawler->filter('title')->count()
);
// Check that the page has a correct title.
$this->assertSame(
'Travel',
$crawler->filter('title')->text()
);
// Check something in the content
$this->assertSame(
'Hello, World!',
$crawler->filter('body > div#content')->text()
);
If you don't have enough information to debug your code, tou can access to the page content which usually contain the error message:
die($this->client->getResponse()->getContent());

How to Implement Resumable Download in Silex

In silex I can do this to force-download a file:
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
$app = new Silex\Application();
// Url can be http://pathtomysilexapp.com/download
$app->get('/download', function (Request $request) use ($app) {
$file = '/path/to/download.zip';
if( !file_exists($file) ){
return new Response('File not found.', 404);
}
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'download.zip');
});
$app->run();
This works well for smaller files. However my use case requires downloading a big that can be paused/resumed by a download manager.
There is an example about file streaming but it doesn't seem to be what I am looking for. Has somebody done this before? I could just use the answer from here and be done with it. But it would be nice if there is a silexy way of doing this.
Implementing it is quite trivial if you have a the file on the drive. It is like paginating records from a table.
Read the headers, open the file, seek to the desired position and read the the size requested.
You only need to know a little bit about the headers from the request & response.
Does the server accept ranges:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
HTTP 206 status for content ranges:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206
Info about the content range headers:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range

How to call wordpress function directly from url?

I have added custom payment method to woocommerce and its working fine . I just have one problem that it calls a callback url for saving transaction information to db. I have created new function for this in my plugin file but i cant excess it directly .
This is how i have done it:
//add_action('wp_ajax_nopriv_payment_callback_action', 'payment_callback_action');
//function
function payment_callback_action() {
echo "Its Working!";
}
I am trying to access it by :
url:"<?=site_url( '/' );?>wp-admin/admin-ajax.php?action=payment_callback_action
It seemd that it because of i dnt have privillage to use it directly but how can i do this ?.
Thanks
# for users not logged in
add_action('wp_ajax_nopriv_payment_callback_action', 'dixipay_callback_action');
# for users logged in
add_action('wp_ajax_payment_callback_action', 'dixipay_callback_action');
# Your callback
function dixipay_callback_action() {
echo "Its Working!";
}
read more: http://codex.wordpress.org/AJAX_in_Plugins

Resources