Grow your CSS skills. Land your dream job.

Fatal error: Out of memory

  • # April 12, 2013 at 2:24 am

    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:

    < ?php
    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/’ . $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.

    __
    # April 12, 2013 at 2:55 am

    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.

    # April 12, 2013 at 1:18 pm

    it wont let me past 100m

    # April 12, 2013 at 5:28 pm

    I would like some help maybe?

    __
    # April 12, 2013 at 5:42 pm

    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?

    # April 12, 2013 at 5:44 pm

    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;`.

    __
    # April 12, 2013 at 6:57 pm

    [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.

    # April 13, 2013 at 2:50 am

    thanks @traq ill try that!

    # April 13, 2013 at 3:14 am

    i found out that it is on the fwrite that it runs out

    __
    # April 13, 2013 at 10:01 am

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

    # April 17, 2013 at 4:53 pm

    No because braking it up causes the error too and the files are 20 min flv

    __
    # April 17, 2013 at 5:10 pm

    > 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?

    # April 17, 2013 at 5:13 pm

    Yes

    __
    # April 17, 2013 at 5:14 pm

    which question are you answering?

    # April 17, 2013 at 5:16 pm

    Ok all questions:
    1 don’t know
    2 20 min flv
    3 yes

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".