Jump to content

unemployment

Members
  • Posts

    746
  • Joined

  • Last visited

Posts posted by unemployment

  1. Do you know of a way in php to do multitrack video editing? The only tool I have found online is a MltMelt, which is a command line utility. I'm in the process of making an app that merges multiple videos, photos and audio clips into one video, but I was wondering if there was a way to process this in php. Can anyone point me to a PHP library that can handle things like multitrack merging, transitions, color effects, blurring, etc?

     

    I'm looking for adobe premier like features in code.

     

  2. I'm in the process of converting images from external websites references to images stored in my amazon S3 account.  I'm running a script to do the conversion for the images I need, however the script continues to break with this error message:

    E_WARNING: imagecreatefromjpeg(http://www.site.org/Ansichtskarten.images/I/AK04659a.jpg): failed to open stream: Connection timed out

    Is there anyway I can have the script just continue running even if there is an error? Restarting the script is frustrating and counterproductive.

    Script:

     

    <?php
    ini_set('memory_limit','2048M');
    ini_set('max_execution_time', 30000000);
    ini_set("user_agent", 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
    ini_set('gd.jpeg_ignore_warning', 1);
    $cron = true;
    include('init.inc.php');
    
    $query = 'SELECT * FROM city_images WHERE city_id > 0 ORDER BY city_id';
    $city_images	= sql::q($query);
    //var_dump($cities); die;
    
    while ($row = sql::f_assoc($city_images)) {
    	
    	//var_dump($row);
    	$city_id =  $row['city_id'];
    	$image = image::resize_upload_amazon_new($row['image'], $row['city_id']);
    	
    	if(!is_array($image)){
    		$sql = "INSERT INTO `city_images_new` (`city_id`, `image`)
    				VALUES ('{$city_id}', '{$image}')";
    			
    		sql::q($sql);
    	}
    	//var_dump($image); die;
    }
    //die;
    echo PHP_EOL . "Images converted succesfully"; die;
    
    ?>
    
  3. I have a running chat application in my website. It is implemented using websockets, php and is working fine. The problem is whenever i send a message to single user it broadcasts that message to all users currently connected to my website. It will be really helpful if someone can tell me how to get the unique id of each user when someone connects to our app. If i can get the userid of the current logged in chat user that would solve my problem but i am unable to retrieve that userid when the user connects (open state of websocket). I can get the userid when the connection is made but I need the userid before the connection happens. When the connecation occurs it assigns its own ids to the connected users in a serial manner(1,2,3..,n).

    <?php
    // prevent the server from timing out
    set_time_limit(0);
    
    // include the web sockets server script (the server is started at the far bottom of this file)
    require 'class.PHPWebSocket.php';
    
    // when a client sends data to the server
    function wsOnMessage($clientID, $message, $messageLength, $binary) {
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );
    
    // check if message length is 0
    if ($messageLength == 0) {
        $Server->wsClose($clientID);
        return;
    }
    
    //Send the message to everyone but the person who said it
    foreach ( $Server->wsClients as $id => $client )
        if ( $id != $clientID )
            $Server->wsSend($id, "Visitor $clientID ($ip) said "$message"");
    }
    
    // when a client connects
    function wsOnOpen($clientID)
    {
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );
    
    $Server->log( "$ip ($clientID) has connected." );
    
    //Send a join notice to everyone but the person who joined
    foreach ( $Server->wsClients as $id => $client )
        if ( $id != $clientID )
            $Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.");
    }
    
    // when a client closes or lost connection
    function wsOnClose($clientID, $status) {
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );
    
    $Server->log( "$ip ($clientID) has disconnected." );
    
    //Send a user left notice to everyone in the room
    foreach ( $Server->wsClients as $id => $client )
        $Server->wsSend($id, "Visitor $clientID ($ip) has left the room.");
    }
    
    // start the server
    $Server = new PHPWebSocket();
    $Server->bind('message', 'wsOnMessage');
    $Server->bind('open', 'wsOnOpen');
    $Server->bind('close', 'wsOnClose');
    // for other computers to connect, you will probably need to change this to your LAN IP or external IP,
    // alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
    $Server->wsStartServer('127.0.0.1', 9300);
    
    ?>
    
    <!doctype html>
    <html>
    <head>
    <meta charset='UTF-8' />
    <style>
        input, textarea {border:1px solid #CCC;margin:0px;padding:0px}
    
        #body {max-width:800px;margin:auto}
        #log {width:100%;height:400px}
        #message {width:100%;line-height:20px}
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="fancywebsocket.js"></script>
    <script>
        var Server;
    
        function log( text ) {
            $log = $('#log');
            //Add text to log
            $log.append(($log.val()?"n":'')+text);
            //Autoscroll
            $log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight;
        }
    
        function send( text ) {
            Server.send( 'message', text );
        }
    
        $(document).ready(function() {
            log('Connecting...');
            Server = new FancyWebSocket('ws://127.0.0.1:9300');
    
            $('#message').keypress(function(e) {
                if ( e.keyCode == 13 && this.value ) {
                    log( 'You: ' + this.value );
                    send( this.value );
                    $(this).val('');
                }
            });
    
            //Let the user know we're connected
            Server.bind('open', function() {
                log( "Connected." );
            });
    
            //OH NOES! Disconnection occurred.
            Server.bind('close', function( data ) {
                log( "Disconnected." );
            });
    
            //Log any messages sent from server
            Server.bind('message', function( payload ) {
                log( payload );
            });
    
            Server.connect();
        });
    </script>
    </head>
    
    <body>
    <div id='body'>
        <textarea id='log' name='log' readonly='readonly'></textarea><br/>
        <input type='text' id='message' name='message' />
    </div>
    </body>
    
    </html>
    
  4. How do you do a simple path rewrite in .htaccess? I need my localhost/blog url to access the content located in localhost/assets/blog . How do I make this rule occur in htaccess?


    My full .htaccess code:



    <IfModule mod_rewrite.c>
    Options +FollowSymlinks -MultiViews
    RewriteEngine On
    </IfModule>

    RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
    RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L,S=4]

    # If requested resource exists as a file or directory, skip next three rules
    RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/$1 -d
    RewriteRule (.*) - [S=3]

    # Blog articles.
    # RewriteCond %{REQUEST_FILENAME} !-f
    # RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteRule ^/?blog/([^/]+)/(\d+)/(\d+)$ blog.php?title=$1&id=$2&reply_to=$3 [L,S=1]

    # RewriteCond %{REQUEST_FILENAME} !-f
    # RewriteCond %{REQUEST_FILENAME} !-d
    # RewriteRule ^/?blog/([^/]+)/(\d+)$ blog.php?title=$1&id=$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(blog/.*)$ /assets/$1 [L,NC]

    # Remove the .php extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

    # for copying
    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^(.*)$ index.php?page=$1 [L]

    RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ app.php?tag=$1 [QSA,L]

    # ----------------------------------------------------------------------
    # Custom 404 page
    # ----------------------------------------------------------------------

    # You can add custom pages to handle 500 or 403 pretty easily, if you like.
    ErrorDocument 403 /error.php?type=403
    ErrorDocument 404 /error.php?type=404
    ErrorDocument 500 /error.php?type=500

  5. I think I have an output buffering issue, but I don't understand it because in my php.ini file I have outbuffering = On .

     

    [05/08/2013 11:16:01] E_WARNING: Cannot modify header information - headers already sent by (output started at /admin.local.com/show.php:1) in /admin.local.com/assets/init.inc.php on line 178

     

    In my init.inc.php file I have:

    <?php
    ob_start();
    session_start();
    
    date_default_timezone_set("America/New_York");
    setlocale(LC_MONETARY, 'en_US.UTF-8'); 
    header('Content-type: text/html; charset=UTF-8');
    
    $timer_start = microtime(true);
    
    $path = dirname(__FILE__);
    
    
    function custom_error_handler($errno, $errstr, $errfile, $errline){
    	if (error_reporting() == 0){
    		return;
    	}
    
    global $error_log_location;
    	
    ob_end_clean();
    
  6. MAMP is giving me the following error:

    E_WARNING: Cannot modify header information - headers already sent by (output started at /Users/jason/Sites/site.com/admin.site.com/show.php:1) in /Users/jason/Sites/trekeffect.com/admin.site.com/assets/init.inc.php on line 8

     

    Do you know why this would happen?

    This is line 8 in init.inc.php:

    header('Content-type: text/html; charset=UTF-8');

    This is line 1 of show.php
     

    <?php
  7. On my startups site you'll notice in the featured destinations section that I have destination images that have a fixed height and width set by using CSS. The problem is that my images do not maintain their proportion, yet I want them at this size and I want them to look good.

    How should I resolve this issue? Should I make sure that all images that are uploaded are cropped at the necessary ratio? If so, can I do this automatically using PHP so that I don't have to manually do it?

     

  8. When I run

     

    $dir = shell_exec('cd /var/www/trekeffect.com/trekeffect.com;pwd');
    
    $this->log($dir);
    //chdir('/trekeffect.com/trekeffect.com');
    //shell_exec('cd /var/www/trekeffect.com/trekeffect.com', $output);
             
    $test = shell_exec('pwd');
    $this->log($test);
    

    It logs:

    2013-04-12 14:36:36-04:00 --- INFO: /var/www/trekeffect.com/trekeffect.com

    2013-04-12 14:36:36-04:00 --- INFO: /var/www/deploy

     

    It seems to be going back to the first deploy directory. Do you know why?

  9. This is my script with the real directory:

    $this->log('Enter Execute');
    //$this->log($this->_directory);
    // Make sure we're in the right directory
    
    //chdir($this->_directory);
    $this->log(getcwd());
    
    //chdir('/trekeffect.com/trekeffect.com');
    shell_exec('cd /var/www/trekeffect.com/trekeffect.com', $output);
    
    $this->log(getcwd());
    
    $this->log('Changing working directory... ');
    
    // Update the local repository
    exec('git pull '.$this->_remote.' '.$this->_branch, $output);
    $this->log('Pulling in changes... '.implode(' ', $output));
    
    // Secure the .git directory
    exec('chmod -R og-rx .git');
    $this->log('Securing .git directory... ');
    
    if (is_callable($this->post_deploy))
    {
      call_user_func($this->post_deploy, $this->_data);
    }
    
    $this->log('Deployment successful.');
    
  10. I've already done that using the below code, but it doesn't work:

     

    $this->log('Enter Execute');
    //$this->log($this->_directory);
    // Make sure we're in the right directory
    
    //chdir($this->_directory);
    $this->log(getcwd());
    
    //chdir('/mysite.com/mysite.com');
    shell_exec('cd /var/www/mysite.com/mysite.com', $output);
    
    $this->log(getcwd());
    
    $this->log('Changing working directory... ');
    
    // Update the local repository
    exec('git pull '.$this->_remote.' '.$this->_branch, $output);
    $this->log('Pulling in changes... '.implode(' ', $output));
    
    // Secure the .git directory
    exec('chmod -R og-rx .git');
    $this->log('Securing .git directory... ');
    
    $this->log('Deployment successful.');
    
  11. Hey guys... I change my script around and for some reason it doesn't seem to be working any more. Do you know why?
     

    $this->log(getcwd());
              
    //chdir('/mysite.com/mysite.com');
    shell_exec('cd /var/www/mysite.com/mysite.com', $output);
             
    $this->log(getcwd());
    
    
    

    The out put for that is:

    2013-04-12 12:21:57-04:00 --- INFO: /var/www/deploy
    2013-04-12 12:21:57-04:00 --- INFO: /var/www/deploy

     

    I don't receive an noticeable errors.  I also tried the chdir function but that kills my script and the second log won't occur.  Any ideas?

  12. I'm in the process of trying to set up automatic deployments when I make a git push to my bitbucket repository. I have a php deploy script that I leveraged from http://brandonsummers.name/blog/2012/02/10/using-bitbucket-for-automated-deployments/ but when the script runs it is logging that it's only updating from a previous commit.

    Here is an example. Let say I log into my server and type git pull. The server will update with the latest changes and lets say the hash for that commit was 001. However if I make serveral commits lets call them 002, 003, and 004 my script should run every time assuming I pushed those changes to bitbucket after every commit. The script runs but every time it will keep the changes from 001. Only when I log into my server and type git pull, will the server update to 004. Do you know what would cause this?

    <?php
    
    $ajax = true;
    include('assets/init.inc.php');
    // date_default_timezone_set('America/Los_Angeles');
    // Also, this Class is not very secure...
    
    $path = dirname(__FILE__);
    
    class Deploy {
    
      /**
      * A callback function to call after the deploy has finished.
      * 
      * @var callback
      */
      public $post_deploy;
      
      /**
      * The name of the file that will be used for logging deployments. Set to 
      * FALSE to disable logging.
      * 
      * @var string
      */
      private $_log = 'deployments.log';
    
      /**
      * The timestamp format used for logging.
      * 
      * @link    http://www.php.net/manual/en/function.date.php
      * @var     string
      */
      private $_date_format = 'Y-m-d H:i:sP';
    
      /**
      * The name of the branch to pull from.
      * 
      * @var string
      */
      private $_branch = 'Master';
    
      /**
      * The name of the remote to pull from.
      * 
      * @var string
      */
      private $_remote = 'origin';
    
      /**
      * The directory where your website and git repository are located, can be 
      * a relative or absolute path
      * 
      * @var string
      */
      private $_directory;
    
      /**
      * The IP address from where BitBucket will be sending the IP address (Davey)
      * 
      * @var string
      */
      private $_ip = '63.246.22.222';
    	
      /**
      * The IP address from where BitBucket will be sending the IP address (Davey)
      * 
      * @var string
      */
      private $_request_method = 'POST';
    	
    /**
      * Error variable for processing
      * 
      * @var bool
      */
      private $_error = false;
    	
      /**
      * Sets up defaults.
      * 
      * @param  string  $directory  Directory where your website is located
      * @param  array   $data       Information about the deployment
      */
      public function __construct($directory, $options = array())
      {
        $this->log('Starting...');
    	
        if (stripos($this->_request_method, $_SERVER['REQUEST_METHOD']) === false)
    	{
    	  $this->_error = true;
    	  $this->log('Request method "'.$_SERVER['REQUEST_METHOD'].'" is not valid', 'ERROR');
    	}
    	else
    	{
    	  $this->log('Request method "'.$_SERVER['REQUEST_METHOD'].'": passed. Checking IP...');
    	  
          if (!empty($_SERVER['REMOTE_ADDR']))
    	  {
    	    if (strlen($this->_ip) > 0) 
    		{
              if (stripos($this->_ip, $_SERVER['REMOTE_ADDR']) !== false)
              {		  
                $this->log('IP "'.$_SERVER['REMOTE_ADDR'].'": passed. Continuing... ');
    		  }
              else
              {
    		    $this->_error = true;
                $this->log('This ip "'.$_SERVER['REMOTE_ADDR'].'" is not allowed', 'ERROR');
    		  }
            }
    
            if ($this->_error !== true)
            {		
    		
              // Determine the directory path
              $this->_directory = realpath($directory).DIRECTORY_SEPARATOR;
          
              $available_options = array('log', 'date_format', 'branch', 'remote');
    
              foreach ($options as $option => $value)
              {
                  if (in_array($option, $available_options))
                  {
                      $this->{'_'.$option} = $value;
                  }  
              }
    
              $this->log('Attempting deployment...');
    		}
    	  }
    	  else
    	  {
    	    $this->log('Missing REMOTE_ADDR', 'ERROR');
    	  }
    	}
      }
    
      /**
      * Writes a message to the log file.
      * 
      * @param  string  $message  The message to write
      * @param  string  $type     The type of log message (e.g. INFO, DEBUG, ERROR, etc.)
      */
      public function log($message, $type = 'INFO')
      {
          if ($this->_log)
          {
              // Set the name of the log file
              $filename = $this->_log;
    
              if ( ! file_exists($filename))
              {
                  // Create the log file
                  file_put_contents($filename, '');
    
                  // Allow anyone to write to log files
                  chmod($filename, 0666);
              }
    
              // Write the message into the log file
              // Format: time --- type: message
              file_put_contents($filename, date($this->_date_format).' --- '.$type.': '.$message.PHP_EOL, FILE_APPEND);
          }
      }
    
      /**
      * Executes the necessary commands to deploy the website.
      */
      public function execute()
      {
          try
          {
              // Make sure we're in the right directory
              exec('cd '.$this->_directory, $output);
              $this->log('Changing working directory... '.implode(' ', $output));
    
              // Discard any changes to tracked files since our last deploy
              exec('git reset --hard HEAD', $output);
              $this->log('Reseting repository... '.implode(' ', $output));
    
              // Update the local repository
              exec('git pull '.$this->_remote.' '.$this->_branch, $output);
              $this->log('Pulling in changes... '.implode(' ', $output));
    
              // Secure the .git directory
              exec('chmod -R og-rx .git');
              $this->log('Securing .git directory... ');
    
              if (is_callable($this->post_deploy))
              {
                  call_user_func($this->post_deploy, $this->_data);
              }
    
              $this->log('Deployment successful.');
          }
          catch (Exception $e)
          {
              $this->log($e, 'ERROR');
          }
      }
    
    }
    
    // This is just an example
    $deploy = new Deploy('/var/www/trekeffect.com/trekeffect.com');
    
    // $deploy->post_deploy = function() use ($deploy) {
       // hit the wp-admin page to update any db changes
       // exec('curl http://www.foobar.com/wp-admin/upgrade.php?step=upgrade_db');
      // $deploy->log('Done.');
    // };
    
    // file_put_contents("{$GLOBALS['path']}/deployments.log", date('c'), FILE_APPEND);
    $deploy->execute();
    
    ?>
    
  13. I have my own custom error code inside of a backbone ajax success method in case the server returns an error. The problem is that this code is repeated throughout my app and I wanted to edit the success function in one place so I don't have to constantly repeat this error handler in every ajax success. I want to edit the success function to include this error check wrapper. Do you know how to do that?

    Here is an example of my success method in one of my views:

     

    "success" : function success(model, data)
    			    {
    				 if(data['error'] !== undefined && data['error'].length === 0)
    				  {
    				   message('error', 'Whoops! System Error. Please refresh your page.');
    				  }
    			    else if(data['error'] !== undefined)
    				 {
    		          message('error', data['error']);
    				 }
    			    else
    				 {
    				  //add templates and do stuff here
    				 }
    			   }
    

     

    Ideally I'd like to set that in a config somewhere and then I'd just be able to use:

     

    "success" : function success(model, data)
    	            {
    				 // add templates and do stuff here
    			    }
    

     

    Is this possible? I tried using ajaxSetup but that didn't seem to work for me.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.