Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Fatal error: Out of memory

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #44058
    Htmlmainiac
    Member

    Hi lovely CSS-TRICKS community,

    I have a problem here i’m trying to use the Usream api to make a search then get the file from their server to mine but i keep getting

    > Fatal error: Out of memory

    even though i did

    ini_set(‘memory_limit’, ’70M’);
    set_time_limit(0);

    And here is my hole code:

    ini_set(‘error_reporting’, E_ALL);
    ini_set(‘memory_limit’, ’70M’);
    set_time_limit(0);

    require_once(‘./func/Zend.php’);

    class UstreamToYouTube {
    private $key = ‘F8CF0D132889AEC1A0D6D14B65B220A9’,
    $title = ‘BochTV’,
    $c,
    $url,
    $options = array(CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0’),
    $reponse,
    $results;

    function __construct() {
    $this->url = ‘http://api.ustream.tv/php/video/recent/search/title:like:’ . urlencode($this->title) . ‘?key=’ . $this->key;
    $this->c = curl_init($this->url);
    curl_setopt_array($this->c, $this->options);
    $this->response = curl_exec($this->c);
    $this->results = unserialize($this->response);
    $this->results = $this->results;
    }

    public function init() {
    $dir = scandir(dirname(__FILE__) . ‘/files/’);
    $i = 0;
    $l = (count($dir) – 1);
    foreach ($this->results as $result) {
    global $i, $l;
    if ($i < $l) {
    global $i, $l;
    $i++;
    } else if ($i == $l) {
    $a = substr($result, 0, 2);
    $b = substr($result, 0, 5);
    $c = $result;
    $d = $result;
    $url = ‘http://upmv09.ntt.upmv.ustream.tv/0/1/&#8217; . $a . ‘/’ . $b . ‘/1_’ . $c . ‘_’ . $d . ‘.flv’;
    $fp = fopen(dirname(__FILE__) . ‘/files/’ . $d . ‘.flv’, “w”);
    $options = array(
    CURLOPT_TIMEOUT => 28800,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true
    );

    print_r($options);

    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    fwrite($fp, curl_exec($ch));
    sleep(3);
    }
    }
    require_once(dirname(__FILE__) . ‘/YouTube.php’);
    }
    }

    $ustoyt = new UstreamToYoutube();
    $ustoyt->init();

    Please can someone tell me why this is happening.

    #131483
    __
    Participant

    Are you on a shared host?

    You probably won’t get this to work without a dedicated server.

    There are any number of places that a configuration might be preventing you from raising the memory limit (at all, or past a certain point). Might be Suhosin, safe_mode (*shudder*), Apache itself … it’s quite common on shared hosts. They don’t want one user hogging the CPU.

    #131650
    __
    Participant

    As I said, if you don’t have a dedicated server, you probably won’t be able to do this.

    Do you have a dedicated server?

    #131651
    CrocoDillon
    Participant

    I’m having a hard time trying to figure out what your init function actually does. And why you declare variables global after defining them in a class method with `global $i, $l;`.

    #131657
    __
    Participant

    [Everything here](http://v1.srcnix.com/2010/02/10/7-tips-to-prevent-php-running-out-of-memory/) is great advice.

    You can also use [gc_collect_cycles()](http://php.net/gc_collect_cycles) to make PHP clean up after itself more often. It _might_ be helpful for you to call that at the beginning of each loop.

    But CrocoDillon is right about that code – there’s about eight lines in a row that repeatedly do the same, nonsensical things.

    #131710
    __
    Participant

    How big are the writes you’re making? Can you break it into smaller chunks and gc between loops?

    #132199
    __
    Participant

    > Do you have a dedicated server?

    .
    > How big are the writes you’re making?

    .
    > And why you declare variables global after defining them in a class method *[?]*
    ( @Crocodillon )

    Did you try gc’ing inside your loop?

    Did you check if there is a server setting limiting the memory you use?

    #132201
    __
    Participant

    which question are you answering?

    #132205
    ghafirsayed
    Member

    Because Htmlmainiac doesn’t know himself what he is asking. He is just spaming on css-tricks , has already made a complain.

    #132206
    ghafirsayed
    Member

    Look here, just entering links(probably assuming that if he enters links twice he would get two backlinks (: )

    https://css-tricks.com/forums/discussion/24241/how-do-you-center-div-in-css#Item_7

    #132209
    Htmlmainiac
    Member

    Sort thought it had croped off the end but I haden’t.

    #132215
    __
    Participant

    > Do you have a dedicated server?
    >> don’t know

    That probably means you don’t.

    Therefore, my first comment applies:

    > You probably won’t get this to work without a dedicated server.

    *****
    > How big are the writes you’re making?
    >> 20 min flv

    That’s not a size.

    What I am asking is how much data (i.e., in *bytes*) you are trying to write at once.

    *****
    > And why you declare variables global after defining them in a class method [?]

    ( @Crocodillon )
    >> yes

    That wasn’t a yes-or-no question.

    *****
    What about garbage collection? Did you try? What were your results?

    *****
    What about your server settings? Did you check on safe mode, Suhosin, or other Apache settings? Ask your web host if you don’t know how to check these things.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Back End’ is closed to new topics and replies.