Forums

  • # 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 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 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 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:14 pm

    which question are you answering?

    # April 17, 2013 at 5:21 pm

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

    # April 17, 2013 at 5:23 pm

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

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

    # April 17, 2013 at 5:31 pm

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

    __
    # April 17, 2013 at 5:58 pm

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

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag