Symfony2: pthreads produces blank page - php

I'm trying to use the extension php_pthreads with Symfony2.
I set up a simple controller:
<?php
namespace Test\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class SimpleThread extends \Thread {
public function run() {
sleep(100);
}
}
class DefaultController extends Controller
{
public function indexAction()
{
$simpleThread = new SimpleThread();
$simpleThread->start();
return $this->render('TestTestBundle:Default:index.html.twig', array('name' => "World"));
}
}
And it just gives me a blank page (ERR_CONNECTION_RESET). I have nothing to try to fix it since there is no error, I don't know how to debug this.
When I try to run this simple test code (https://stackoverflow.com/a/15501449/3070307) outside of Symfony, it works fine.
Any help is much appreciated.
EDIT:
Ok two things:
sleep(100);
Sleeps for 100 seconds... I miss-typed usleep.
Second, the Symfony cache is messing with thread execution apprently, disabling it fixed it (http://symfony.com/doc/current/cookbook/debugging.html).
The only remaining problem is the render function does nothing, I'm not even sure it's called.

Related

PHP class not found in Laravel controller

I'm having an issue within a Laravel controller, I'm not sure where to begin troubleshooting. Basically 2 separate methods are calling the same external class; the process method works, however when calling process3d I run into the error class 'App\Services\PaymentGateway\Gateway\RequestGatewayEntryPointList' not found.
DebugController.php
namespace App\Http\Controllers;
use App\Services\PaymentGateway\Gateway\RequestGatewayEntryPointList;
...
public function process(Request $request) {
...
$rgeplRequestGatewayEntryPointList = new RequestGatewayEntryPointList;
...
}
public function process3d(Request $request) {
...
$rgeplRequestGatewayEntryPointList = new RequestGatewayEntryPointList;
...
}
PaymentSystem.php
namespace App\Services\PaymentGateway\Gateway;
...
class RequestGatewayEntryPointList {
...
}
I've omitted irrelevant code to keep the question brief, but I'm of course happy to provide more details if it will help.
What's going on?
Found it 5 minutes after posting to stackoverflow... oops.
process3d was missing require_once DIR.'/../../Services/PaymentGateway/Gateway/PaymentSystem.php';
Adding this solved the issue.

Laravel second test fails

I have one test case with two tests in it like so:
class LoginTest extends TestCase {
use DatabaseMigrations;
public function testSeeLoginForm() {
$this->visit('/backend');
}
public function testCanLogin() {
$this->visit('/backend');
}
}
The 2 tests are identical but the first one passes and the second one fails with a 404 (A request to [http://localhost/backend] failed. Received status code [404].)
What am I doing wrong?
After a long journey searching for the problem I finally fixed it.
Apparently, when testing routes, using require_once instead of require breaks the testing.

Call to undefined method Session::has() in Laravel 5 + Codeception functional testing

I was running some functional tests in Laravel 5 with Codeception.
Below is a sample test
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class HomePageTestCest
{
use WithoutMiddleware;
public function _before(FunctionalTester $I)
{
//some setup to run
}
public function _after(FunctionalTester $I)
{
}
// tests
public function tryToTest(FunctionalTester $I)
{
$I->wantToTest('If i can go to home page without errors');
$I->amOnPage('/');
$I->canSee('WELCOME TO HOMEPAGE');
}
}
But i am getting below error while running the test:
Fatal error: Call to undefined method Session::has() in /var/www/laravel5/storage/framework/views/e7953b3ce9b90e51d4cfdb279790953bbe25dc9a.php on line 225
And in line 225 i have:
<?php if(Session::has('someKey')): ?>
//some html code
<?php endif; ?>
I think the problem is with session driver. I also tried to implement this but nothing changed.
Hope will get some help. Thanks in advance.
In LARAVEL 5.2 they also create the session class like helper
where in you can make use of it like this
session()->has('key')
See DOCUMENTATION SESSION
namespace App\Http\Controllers;
// import session class using alias
use Session;
class SampleController exntends Controller {
public function __construct() {
}
public function index() {
// print session values
var_dump(Session::all());
}
}
Thanks to hamedmehryar for the solution. I dont know why but for some reason i have to define whole namespace for the facades, even they are already defined in 'aliases' inside config/app.php. For example:
Session::has()
should be like
Illuminate\Support\Facades\Session::has()
I explained it here so if anyone face this problem will be able to solve it from here.
Do not forget
use Illuminate\Http\Request;.
AND use session like this
$request->session()->has('key');

Attempting to use custom facade results in 'Call to undefined method' on Application::create() in Laravel?

I am attempting to create my own custom facade for a Search feature, but I'm having a little difficulty:
type: Symfony\Component\Debug\Exception\FatalErrorException
message: Call to undefined method Illuminate\Foundation\Application::create()
file: H:\myproj\vendor\laravel\framework\src\Illuminate\Container\Container.php
line: 165
This error is caused by my code hitting:
Search::indexObject();
Where my Search facade is set up as follows:
SearchServiceProvider
<?php
namespace MyProj\Search;
use Illuminate\Support\ServiceProvider;
class SearchServiceProvider extends ServiceProvider {
public function register() {
$this->app->bind('search', 'MyProj\Search\Search');
}
}
Search Facade
<?php
namespace MyProj\Facades;
use Illuminate\Support\Facades\Facade;
class Search extends Facade {
public static function getFacadeAccessor() {
return 'search';
}
}
Search class
<?php
namespace MyProj\Search;
use Elasticsearch\Client;
use Credential;
class Search {
private $elasticSearchClient;
public function __construct() {
$this->elasticSearchClient = new Client(array(
'hosts' => [Credential::ElasticSearchHost]
));
}
public function indexObject($object) {
// Code
return $this->elasticSearchClient->index($params);
}
public function get() {
return $this->$elasticSearchClient;
}
}
I have run composer dump-autoload without success, and my facade and service provider is loaded in app.php as follows:
Aliases array
'Search' => 'MyProj\Facades\Search',
Providers array
'MyProj\Search\SearchServiceProvider'
I've spent the past 30 minutes debugging and searching for this error without any fix. What's going on here?
EDIT: I've added in the stack trace, which you can see below. Additionally, I can see that getFacadeAccessor() is being called correctly, but anything beyond that is outside of my understanding.
The highlighted frame represents the last occurrence of normal operation, both frames on Handler.php represent the formatting and outputting of the error at the top of the question.
Appreciate this is a bit of an old thread, however you'd get the problems described if you compiled cache wasn't cleared after adding your new Facade.
You should run:
php artisan clear-compiled

Symfony 2: Class not found in Controller

I've been struggling with this for some time now. It is most likely a rookie/typo problem, but I just can't find it.
I have this class ...
<?php
namespace PriceOrQuality\POQBundle\RegExConf;
use PriceOrQuality\POQBundle\RegExConf\RegExConf;
class RegExConfIrma extends RegExConf {
public function __construct() {
$this->start_page = 'https://irma.dk';
$this->startConnection();
$this->getAllLinks();
}
}
?>
that I'm trying to load from this controller.
<?php
// src/PriceOrQuality/POQBundle/Controller/CrawlerController.php;
namespace PriceOrQuality\POQBundle\Controller;
use PriceOrQuality\POQBundle\RegExConf\RegExConfIrma;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Monolog\Logger;
use Monolog\Handler\FirePHPHandler;
Class CrawlerController extends Controller {
public function testAction($page) {
if($page == 'irma') {
$regex = new RegExConfIrma();
return $this->render('PriceOrQualityBundle:Crawling:crawling_test.html.twig', array('links' => $regex->getLinks()));
}
}
}
?>
However I get this error, and I just cannot seem to find the problem.
FatalErrorException: Error: Class 'PriceOrQuality\POQBundle\RegExConf\RegExConfIrma' not found in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/Controller/CrawlerController.php line 16
The RegExConfIrma resides in /Users/Rune/Sites/poq/src/PriceOrQuality/POQBundle/RegExConf/RegExConfIrma
I've tried to debug:
* the namespace
* clearing cache
* changing the namespace
But nothing helps.
Any help is highly appreciated.
Thanks!
The problem was extremely rookie.
I forgot to add .php after my file extension as I use Netbeans where the logo showed is as a php file, but without the proper extension.
So for anyone else finding this post with the same problem:
Make sure you use the right namespace
Make sure you include or usethe class
Make sure of the spelling of the class
Make sure the
filename is spelled exactly the same as the class
Make sure you've
added .php after the class file

Categories