Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:49:51+00:00 2026-06-11T12:49:51+00:00

in my doctrine table i got this public function countHitsFor($object_id) { return $this->createQuery(‘s’) ->select(‘COUNT(*)

  • 0

in my doctrine table i got this

public function countHitsFor($object_id) {
  return $this->createQuery('s')
       ->select('COUNT(*) as count')
       ->where('s.target_id = ?', $object_id);
       ->useResultCache(true, 3600, 'hits_for_'.$object_id)
       ->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);
}

so if i use this from action its works fine,
first request make sql query,
second load Hits from cache

and what i want is to warm up cache from symfony task

i start task and for each object i call StatTable::getInstance()->countHitsFor($object_id) to create cache data for query, but its not works

after task first request to action makes sql query

UPD

ProjectConfiguration

public function configureDoctrine(Doctrine_Manager $manager)
{
    $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, new Doctrine_Cache_Apc());
}

task

<?php

class warm_up_stat_cacheTask extends sfProgressTask
{

protected function configure()
{

    $this->addOptions(array(
        new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
        new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'prod'),
        new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
            // add your own options here
    ));

    $this->namespace = 'my_tasks';
    $this->name = 'warm_up_stat_cache';
    $this->briefDescription = '';
    $this->detailedDescription = '';
}

protected function execute($arguments = array(), $options = array())
{
    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
    $contextInstance = sfContext::createInstance($this->configuration);

    $Objects = ObjectTable::getInstance()->findAll();

    foreach ($Objects as $obj) {
        StatTable::getInstance()->countHitsFor($obj->id);
    }
    $obj->free();

    }
}

comand

php symfony my_tasks:warm_up_stat_cache

UPD2

as i understand the problem is in APC

public function countHitsFor($object_id) {
  $ckey = 'hits_for_'.$object_id;

  if (!apc_exists($ckey))
     apc_store($ckey,$this->createQuery('s')
       ->select('COUNT(*) as count')
       ->where('s.target_id = ?', $object_id);
       ->useResultCache(true, 3600, 'hits_for_'.$object_id)
       ->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR));

  return (int) apc_fetch($ckey);
}

this not works too, may be APC makes prefixes for keys for different environments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:49:53+00:00Added an answer on June 11, 2026 at 12:49 pm

    The problem is in Apc, its use separate memory spaces for Apache (mod_php) and for Cli.

    I made simple key-value storage on MyISAM table.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

InSymfony (Doctrine) I am trying to create a public function with the code below.
In table class Ouders I do the following query: $q = $this->createQuery('o') ->where('o.ouderid IN
Symfony 2, Doctrine 2.1. I've got 3 entities, one of them intermediate (join table).
I get table - $data = Doctrine::getTable('product_catalog')->findAll(); this table (product_catalog) i link table. has
I found a very useful Doctrine function to set an attribute on a table
Let's imagine something like this: class MyTable extends Doctrine_Table { public function construct() {
I have got a post table and it's schema is like this: CREATE TABLE
I've got this model: /** @Entity @Table(name=articles) */ class Article { /** @Id @GeneratedValue
I'm using Doctrine 2 and single table inheritance, my topmost entity hierarchy is: JS_File
I'm new to Doctrine and ActiveRecord. How should I filter a table after it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.