Ergebnis 1 bis 15 von 15

Thema: Session start error with event listener

  1. #1
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard Session start error with event listener

    First, I apologize for writing in English. I am trying to implement custom insert tags. When I add an event listener, however, I get a runtime ’Failed to start the session because headers have already been sent’ error at line 1. I haven’t been able to find any information that would suggest what I am doing incorrectly. This error occurs even with an event listener that simply returns false. I will appreciate any insight you can provide.

    PHP-Code:
    namespace App\EventListener;

    use 
    Contao\CoreBundle\ServiceAnnotation\Hook;
    use 
    App\Classes\Collections;
    use 
    App\Model\CollectionModel;
    use 
    App\Model\CollectionitemModel;
    use 
    Contao\StringUtil;

    /**
     * @Hook("replaceInsertTags")
     */
    class ReplaceInsertTagsListener
    {    

         
    /**
         *
         * @return string|false
         */
        
    public function __invoke(string $insertTag,
            
    bool $useCache,
            
    string $cachedValue,
            array 
    $flags,
            array 
    $tags,
            array 
    $cache,
            
    int $_rit,
            
    int $_cnt)
        {
            return 
    false;
        }


  2. #2
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Zitat Zitat von ldisilvestro Beitrag anzeigen
    First, I apologize for writing in English.
    No need to apologize. We know that the English community forum has technical difficulties.


    Zitat Zitat von ldisilvestro Beitrag anzeigen
    When I add an event listener, however, I get a runtime ’Failed to start the session because headers have already been sent’ error at line 1. I haven’t been able to find any information that would suggest what I am doing incorrectly. This error occurs even with an event listener that simply returns false.
    That error message is just an after-effect of a pre-cursing error. I would recommend to enable the Debug Mode in order to possibly find out more about your original error.
    » sponsor me via GitHub or PayPal or Revolut

  3. #3
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard Nature of error

    It is by running in Debug mode that I was able to determine the nature of the error to the extent that I did. Debug mode reports no other error to me. When I remove the event listener, there are no errors. Here is the stack trace:
    Code:
    RuntimeException:
    Failed to start the session because headers have already been sent by "/src/EventListener/InsertTagsListener.php" at line 1.
    
      at vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:152
      at Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
         (vendor/symfony/http-foundation/Session/Session.php:57)
      at Symfony\Component\HttpFoundation\Session\Session->start()
         (vendor/contao/core-bundle/src/Framework/ContaoFramework.php:208)
      at Contao\CoreBundle\Framework\ContaoFramework->setConstants()
         (vendor/contao/core-bundle/src/Framework/ContaoFramework.php:156)
      at Contao\CoreBundle\Framework\ContaoFramework->initialize(true)
         (vendor/contao/core-bundle/src/Routing/Matcher/LegacyMatcher.php:59)
      at Contao\CoreBundle\Routing\Matcher\LegacyMatcher->matchRequest(object(Request))
         (vendor/symfony-cmf/routing/src/DynamicRouter.php:278)
      at Symfony\Cmf\Component\Routing\DynamicRouter->matchRequest(object(Request))
         (vendor/symfony-cmf/routing/src/ChainRouter.php:188)
      at Symfony\Cmf\Component\Routing\ChainRouter->doMatch('/collections.html', object(Request))
         (vendor/symfony-cmf/routing/src/ChainRouter.php:158)
      at Symfony\Cmf\Component\Routing\ChainRouter->matchRequest(object(Request))
         (vendor/symfony/http-kernel/EventListener/RouterListener.php:112)
      at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
         (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:126)
      at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
         (vendor/symfony/event-dispatcher/EventDispatcher.php:264)
      at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
         (vendor/symfony/event-dispatcher/EventDispatcher.php:239)
      at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
         (vendor/symfony/event-dispatcher/EventDispatcher.php:73)
      at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
         (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:168)
      at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
         (vendor/symfony/http-kernel/HttpKernel.php:134)
      at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
         (vendor/symfony/http-kernel/HttpKernel.php:80)
      at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
         (vendor/symfony/http-kernel/Kernel.php:201)
      at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
         (web/index.php:31)

  4. #4
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Is that the whole content of your src/EventListener/InsertTagsListener.php that you posted? If yes, then it is missing the beginning <?php Tag, that all PHP files need to have. Make sure that no other whitespace is in front of it.

    If no, then the file might contain a BOM in the beginning. You need to make sure that your editor of choice saves files without a BOM.
    Geändert von Spooky (02.03.2021 um 17:08 Uhr)
    » sponsor me via GitHub or PayPal or Revolut

  5. #5
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    I remain unable to determine what I am doing wrong.
    Geändert von ldisilvestro (02.03.2021 um 17:21 Uhr)

  6. #6
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    Thanks so much for your help. I don't want to impose, though. Do you have a process whereby people like myself can request debugging assistance? My site appears to be working well until I add the event listener.

  7. #7
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Just keep posting here . What kind of error do you experience now?
    » sponsor me via GitHub or PayPal or Revolut

  8. #8
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    In truth, I have no idea what is going on. The site *appeared* to work well until I added my event listener, at which point I got a 404 error. In debug mode, there was no on-screen error reported; however, the log potentially suggested routing issues (although I am far from certain). Accordingly, I created the shell event listener as a debugging approach, and ended up introducing the runtime error. Now I am back to the original 404 error, which typically is the result of one of my frequent typos. In debug mode the page displays correctly (but without the custom CSS). I am an archaeologist, not a developer, and suspect that I have made an embarrassing mistake out of ignorance or have a typo outside of the event listener that manifests only when I add the event listener.

  9. #9
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    Here is the situation in more detail:
    - My front-end modules execute without error until I add an event listener (intended to replace insert tags).
    - When I add the event listener (including a presumably benign one that simply returns false), my front-end custom listing modules do not execute, and the display of pages with my custom readers fails with a 404 error. No errors are logged.
    - When I run in debug mode, the front-end modules execute *without* error (except that the custom CSS doesn't load).
    Do you have any recommendations on how I might isolate this issue? Given that my controllers execute without error when in debug mode, I am wondering if there is something the debugger is doing that I am failing to do in my controllers... Would an exception listener enable me to determine what is triggering the 404?

  10. #10
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Did you run composer install after creating your Hook?
    » sponsor me via GitHub or PayPal or Revolut

  11. #11
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    Thank you. I have been using Contao Manager to rebuild the production and development caches and run the install tool. Do I need to learn about Composer and command line consoles in order to use Contao hooks? I did 'Run Installer' from the Composer Dependencies section of the Contao Manager, but the installation had no apparent effect.
    Geändert von ldisilvestro (03.03.2021 um 18:02 Uhr)

  12. #12
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Zitat Zitat von ldisilvestro Beitrag anzeigen
    I did 'Run Installer' from the Composer Dependencies section of the Contao Manager, but the installation had no apparent effect.
    That should suffice, yes.
    » sponsor me via GitHub or PayPal or Revolut

  13. #13
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    Thank you. I apologize for not understanding. I just ran composer install again, and the situation remains the same (non-execution of my controllers and 404 errors with nothing logged).

  14. #14
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    34.063
    Partner-ID
    10107

    Standard

    Do you have the site publicly available somewhere?
    » sponsor me via GitHub or PayPal or Revolut

  15. #15
    Contao-Nutzer
    Registriert seit
    02.03.2021.
    Beiträge
    9

    Standard

    Yes. Which state do you want it in? (With or without the event listener?) It is at https://collections.yoresequoia.org, and currently does not have the event listener installed. I am hoping to use the site to manage my data and share them with my colleagues.
    Geändert von ldisilvestro (03.03.2021 um 18:57 Uhr)

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •